In "git checkout -- files", what does "--" mean?
Is it the "end of option" I am used to see in ba开发者_运维百科sh (and if yes, why do we use it) or is it a Git notation for the Index or the HEAD?
The --
separates the paths from the other options. From the documentation:
git checkout [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>...
If this notation didn't exist the following two commands would be ambiguous:
git checkout <tree-ish> <path1> <path2>
git checkout <path1> <path2> <path3>
With the --
notation it is clear which is meant:
git checkout <tree-ish> -- <path1> <path2>
git checkout -- <path1> <path2> <path3>
The documentation I linked to above includes an example of when you might need it:
$ git checkout hello.c
If you have an unfortunate branch that is named hello.c, this step would be confused as an instruction to switch to that branch. You should instead write:
$ git checkout -- hello.c
精彩评论