特殊的“选项” --表示“将这之后的每个参数作为文件名进行处理,无论它是什么样。” 这不是特定于Git的,它是通用的Unix命令行约定。通常,您使用它来阐明参数是文件名而不是选项,例如
rm -f # does nothing
rm -- -f # deletes a file named "-f"
git checkout1还--意味着后续参数不是其可选的“ treeish”参数,用于指定所需的提交。
因此,在这种情况下,始终使用是安全的--,但是当要还原的文件的名称以开头或与分支的名称相同时,则需要使用它-。分支/文件消除歧义的一些示例:
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"
如果您有一个名称以开头的分支,我不确定您会怎么做-。也许首先不要这样做。
在此模式下为1;“结帐”还可以做其他几件事。我从来没有理解过为什么git选择实现“放弃未提交的更改”作为“ checkout”子命令的模式,而不是像大多数其他VCS那样“还原”或“重置”,我认为这可能对git本身来说更有意义。