I am learning the try git by code school
, and to the unit 1.17 Undo it use the command line
git checkout -- octocat.txt
and the octocat.txt is a file then and it explain that the two dash lines is
It's simply promising the command line that there are no more options after the '--'. This way if you happen to have a branch named octocat.txt, it will still revert the file, instead of switching to the branch of the same name.
but what I cannot understand is that what does it means by no options? And since there are no options after, why it can distinguish it by file from branch?
This answer is not useful. Show activity on this post. The double dash "--" means "end of command line flags" i.e. it tells the preceding command not to try to parse what comes after command line options. Follow this answer to receive notifications.
The double dash -- in git means different things to different commands, but in general it separates options from parameters. In git specifically, the meaning of -- depends on which subcommand you are using it with.
The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.
--
means stop processing options, and even if something does look like an option, e.g. --help
, it should be treated as usual parameter, like file name instead.
Using this syntax, you can actually add or remove file which is called say --help
, which would be impossible otherwise.
In git syntax, --
is also usually used to specify affected files. For example, git checkout something
could mean either checkout branch named something
or file called something
. If you use git checkout -- something
, it always means file, not branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With