git show file with rename detection(相当于git log --follow)
我想在重命名完成之前(当然是自动检测)看到过去重命名的文件的内容。git show file with rename detection(相当于git log --follow)
With git log --follow foo_renamed.txt
and git show master~20 foo_original_name.txt
我可以确认git能够跟踪文件重命名并且文件存在于master~20
中。然而,
git show --follow master~20:foo_renamed.txt
和
git show -M master~20:foo_renamed.txt
都失败,
致命:路径 'foo_renamed.txt' 存在于磁盘上,而不是在 '高手〜20'。
这实际上是有道理的,因为对象规范是<rev>:<path>
BLOB但没有-- /file/path
选项git show
。任何其他方式?谢谢。
不幸的是,没有。只有git log --follow
实现了特殊情况hack来跟踪这些类型的检测到的重命名(它们必须被检测到,一次一个地提交,而在回溯历史时),并且它用不太适合该任务的代码来执行。
如果你想在Git上工作,应该可以修改代码使其更加灵活,并且可以添加一个选项git show
,你可以给git show
一个提交的ID,它是目标提交的后代,但确实有有文件。然后,Git将不得不按照git log
的方式进行修改,执行重命名检测(但使用更灵活的代码),以便当commit-graph walk达到要显示的提交时,Git将能够使用更早的名称。
调用可能是这样的:
git show --follow[=<start>] commit -- path
其中<start>
默认为HEAD
。不过,这是一件不平凡的事情。
(另外,git show
应该拒绝--follow
现在;事实上,它允许它在所有是一个小错误。)
我相信,如果托雷克说git show
不能做到这一点,现在这是当前情况。
我现在的解决方法是:
git show master~42:`git log --follow master~42..master \
--name-only --oneline -- path/to/file | tail -n1`