Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git two dashes means with no more options

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?

like image 348
Jason Avatar asked Jul 23 '13 03:07

Jason


People also ask

What does double dash mean in git?

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.

What is dash in git?

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.

What is git checkout --?

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.


1 Answers

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

like image 146
mvp Avatar answered Oct 17 '22 07:10

mvp