"git checkout"和"git checkout"之间有什么区别?

cla*_*219 0 git

在git下你修改一些文件,使用git status,出现以下消息:

On branch dev
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   script.php
Run Code Online (Sandbox Code Playgroud)

因此,我通常会git checkout -- script.php按照建议撤消我的修改.

无论如何,我从一位同事身上发现,这git checkout script.php似乎可以达到同样的效果.

所以,我的问题是:是git checkout -- script.phpgit checkout script.php同义词,还是没有?

请至少提供一些证明您所说内容的文档的链接.谢谢!

Pau*_*aul 7

如果您有标记或分支命名script.php,那么git checkout script.php将签出该标记或分支,同时git checkout -- script.php将签出当前分支中的文件.

  • @ clami219这也在`git help checkout`手册页中明确说明,例如#1. (3认同)