为什么“git log -?- foo”不适用于已删除的文件 foo?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3197416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:41:18  来源:igfitidea点击:

Why doesn't "git log -?- foo" work for deleted file foo?

gitgit-log

提问by user385804

My repository underwent changes such as:

我的存储库进行了更改,例如:

  1. ...some unrelated commits...
  2. Commit new file foowith 100 lines of content
  3. ...intervening commits, some of which touch foo...
  4. Insert the contents of fooat the top of an existing file barand git rm fooin the same commit
  5. ...more unrelated commits...
  1. ...一些不相关的提交...
  2. 提交foo包含 100 行内容的新文件
  3. ...干预提交,其中一些涉及foo...
  4. foo在现有文件的顶部bargit rm foo同一个提交中插入 的内容
  5. ...更多无关的提交...

Now I want to see the log of deleted file foo. Everything I've read, including on SO, says I should be able to git log -- foo, but that command produces no output.

现在我想查看已删除文件的日志foo。我读过的所有内容,包括 SO 上的内容,都说我应该能够git log -- foo,但该命令不产生任何输出。

If I find the commit that includes deleting fooI can git log 1234abcd -- fooand see its log, so I think my path to fooisn't the problem. Also note that git merge-base HEAD 1234abcdoutputs 1234abcd[...], so I think that should prove the commit is reachable from HEAD. Note that there is no file fooin my working tree (obvious, since it was deleted). Using Git 1.7.1.1 on OS X.

如果我找到包含删除的提交,foo我可以git log 1234abcd -- foo看到它的日志,所以我认为我的路径foo不是问题。还要注意git merge-base HEAD 1234abcd输出1234abcd[...],所以我认为应该证明可以从HEAD. 请注意,foo我的工作树中没有文件(很明显,因为它已被删除)。在 OS X 上使用 Git 1.7.1.1。

Why doesn't git log -- foowork for me and how can I fix it? Thanks!

为什么git log -- foo对我不起作用,我该如何解决?谢谢!

回答by Nathan Kleyn

You want to use the --followoption on git log, which is described in the man page as:

您想使用--followon 选项git log,它在手册页中描述为:

Continue listing the history of a file beyond renames.

Effectively, not only does this allow you to see the history of a renamed file, but this also allows you to view the history of a file no longer in the working tree. So the command you should use should look something like:

实际上,这不仅允许您查看重命名文件的历史记录,而且还允许您查看不再位于工作树中的文件的历史记录。所以你应该使用的命令应该是这样的:

git log --follow -- foo

Update:

更新:

Git 2.9+ has now enabled this by default for all git diffand git logcommands:

Git的2.9+现在已经在默认情况下为所有启用此git diffgit log命令:

The end-user facing Porcelain level commands in the "git diff" and "git log" family by default enable the rename detection; you can still use "diff.renames" configuration variable to disable this.

“git diff”和“git log”系列中面向最终用户的Porcelain级命令默认启用重命名检测;您仍然可以使用“diff.renames”配置变量来禁用它。

Thanks to x-yuri for the heads up!

感谢 x-yuri 的提醒!