【问题标题】:What's the difference between "git checkout" and "git checkout --"? [duplicate]“git checkout”和“git checkout --”有什么区别? [复制]
【发布时间】:2014-05-23 10:55:44
【问题描述】:

当你在 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

所以我通常按照建议使用git checkout -- script.php 撤消我的编辑。

无论如何,我从一位同事那里发现,git checkout script.php 似乎实现了相同的结果。

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

请至少提供一些文档的链接,以证明您所说的。谢谢!

【问题讨论】:

标签: git


【解决方案1】:

如果您有名为script.php 的标签或分支,则git checkout script.php 将检出该标签或分支,而git checkout -- script.php 将检出当前分支中的文件。

【讨论】:

  • 有道理...但是您能提供一些链接来支持您刚刚写的内容吗?为了接受您的回答,我想确保没有其他内容。
  • @clami219 这在git help checkout 手册页中也有明确说明,示例#1。
猜你喜欢
  • 2018-11-23
  • 2022-11-10
  • 2011-04-08
  • 1970-01-01
  • 2011-12-20
  • 2020-03-05
  • 2011-11-10
  • 1970-01-01
相关资源
最近更新 更多