特殊的“选项”--
意思是“将这一点之后的每个参数都视为文件名,无论它看起来像什么。”这不是 Git 特有的,而是通用的 Unix 命令行约定。通常,您使用它来澄清参数是文件名而不是option, e.g.
rm -f # does nothing
rm -- -f # deletes a file named "-f"
git checkout
1 also takes --
to mean that subsequent arguments are not its optional "treeish" parameter specifying which commit you want.
所以在这种情况下safe to use --
总是,但你need当您要恢复的文件的名称以以下开头时-
,或与分支名称相同。分支/文件消歧的一些示例:
git checkout README # would normally discard uncommitted changes
# to the _file_ "README"
git checkout master # would normally switch the working copy to
# the _branch_ "master"
git checkout -- master # discard uncommitted changes to the _file_ "master"
和选项/文件消歧:
git checkout -p -- README # interactively discard uncommitted changes
# to the file "README"
git checkout -- -p README # unconditionally discard all uncommitted
# changes to the files "-p" and "README"
我不确定如果你有的话你会做什么branch谁的名字开头-
。也许一开始就不要这样做。
1 in this mode; "checkout" can do several other things as well. I have never understood why git chose to implement "discard uncommitted changes" as a mode of the "checkout" subcommand, rather than "revert" like most other VCSes, or "reset" which I think might make more sense in git's own terms.