为什么“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
Why doesn't "git log -?- foo" work for deleted file foo?
提问by user385804
My repository underwent changes such as:
我的存储库进行了更改,例如:
- ...some unrelated commits...
- Commit new file
foo
with 100 lines of content - ...intervening commits, some of which touch
foo
... - Insert the contents of
foo
at the top of an existing filebar
andgit rm foo
in the same commit - ...more unrelated commits...
- ...一些不相关的提交...
- 提交
foo
包含 100 行内容的新文件 - ...干预提交,其中一些涉及
foo
... foo
在现有文件的顶部bar
和git rm foo
同一个提交中插入 的内容- ...更多无关的提交...
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 foo
I can git log 1234abcd -- foo
and see its log, so I think my path to foo
isn't the problem. Also note that git merge-base HEAD 1234abcd
outputs 1234abcd[...]
, so I think that should prove the commit is reachable from HEAD
. Note that there is no file foo
in 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 -- foo
work for me and how can I fix it? Thanks!
为什么git log -- foo
对我不起作用,我该如何解决?谢谢!
回答by Nathan Kleyn
You want to use the --follow
option on git log
, which is described in the man page as:
您想使用--follow
on 选项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 diff
and git log
commands:
Git的2.9+现在已经在默认情况下为所有启用此git diff
和git 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 的提醒!