15

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?

1 Answer 1

23

-- 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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.