如何防止git log - 跟随副本,但只跟着重命名?

时间:2017-05-20 08:48:56

标签: git logging copy

如果我正在复制文件而不更改其内容,git log --follow将始终跟随复制源,无论我指定哪个-Cxxx%。如何防止Git完全关注副本,但仍然遵循重命名?

整个存储库的示例日志显示在提交filec.txt中添加了53d9862f

$ git log --format=oneline --stat
e26820a3a80f1f85248cf0c5865a772546022324 modification 4
 filec.txt | 1 +
 1 file changed, 1 insertion(+)
05ac468e19fbf382a0ff4aff1501d0d1b5217ea2 modification 3
 filec.txt | 1 +
 1 file changed, 1 insertion(+)
a4cf5e076055399aa4a97bec61e1be7e972a905f other change
 other.txt | 3 +++
 1 file changed, 3 insertions(+)
53d9862f8e244497c4d0dfd8b6ada9dce45b6e33 copy
 filec.txt | 5 +++++
 1 file changed, 5 insertions(+)
ddd9b8d4cd8c22f9a673084c94eeec97c4d51542 modification 2
 file.txt | 1 +
 1 file changed, 1 insertion(+)
af8be46361c349b261e649920d1b28efdcad542d modification 1
 file.txt | 1 +
 1 file changed, 1 insertion(+)
c225a05105840dd348433cde65d4ba650a6cbb04 initial import
 file.txt | 3 +++
 1 file changed, 3 insertions(+)

文件日志显示过去不应该执行53d9862f的历史记录:

$ git log --format=oneline --follow filec.txt
e26820a3a80f1f85248cf0c5865a772546022324 modification 4
05ac468e19fbf382a0ff4aff1501d0d1b5217ea2 modification 3
53d9862f8e244497c4d0dfd8b6ada9dce45b6e33 copy
ddd9b8d4cd8c22f9a673084c94eeec97c4d51542 modification 2
af8be46361c349b261e649920d1b28efdcad542d modification 1
c225a05105840dd348433cde65d4ba650a6cbb04 initial import

1 个答案:

答案 0 :(得分:1)

事实证明没有直接的方法来打败它,因为它在Git源代码中是硬编码的(至少通过Git 2.13)。

作为一种变通方法,您可以在Git切换到另一个文件的提交之前重新启动git log --follow。在您的示例中,git log --format=oneline --follow filec.txt在提交53d9862f8e244497c4d0dfd8b6ada9dce45b6e33后切换后,您可以运行git log --oneline --follow filec.txt 53d9862f8e244497c4d0dfd8b6ada9dce45b6e33^。这有点痛苦,在我看来应该有办法让git log --follow不跟随副本,但没有。