我正在学习 通过代码学校尝试 git
,并在 1.17 单元使用命令行撤消它
git checkout -- octocat.txt
然后 octocat.txt 是一个文件,它说明两条虚线是
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.
但是我不明白的是,no options是什么意思? 既然后面没有选项,为什么它可以通过文件和分支来区分呢?
最佳答案
--
表示停止处理选项,即使某些东西看起来像一个选项,例如--help
,它应该被视为普通参数,而不是文件名。
使用此语法,您实际上可以添加或删除名为 say --help
的文件,否则这是不可能的。
在git语法中,--
也常用于指定受影响的文件。例如,git checkout something
可能意味着 checkout 名为 something
的分支或名为 something
的文件。如果你使用 git checkout -- something
,它总是意味着文件,而不是分支。
关于git 两个破折号表示没有更多选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17800994/