2017-05-20 26 views
0

如果我在不更改其內容的情況下複製文件,git log --follow將始終跟隨複製源,無論我指定哪個-Cxxx%。如何防止Git完全跟隨副本,但仍然遵循重命名?如何防止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 
+0

...不要設置「檢測複製」選項嗎? (注意,如果你已經配置了這個,可能需要重寫'diff.renames = copy';使用'git -c diff.renames = true log ...'來做到這一點。)(這個註釋被糾正了;我使用了'diff .rename'而不是'diff.renames'。) – torek

+0

不幸的是,這是行不通的。 'git -c diff.renames = true log --format = oneline --follow filec.txt'仍顯示提交。即使'-C diff.renames = false'也沒有效果。 – mstrap

+1

Aha,'try_to_follow_renames'(在'tree-diff.c'中,任何時候'--follow'都有效)在內部強制設置'--find-copies-harder'。無法關閉此功能。如果文件是副本,Git總是切換到副本。 (這看起來像一個錯誤:你應該能夠單獨設置或清除複製發現,即使它默認爲「設置」爲這種情況。) – torek

回答

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不復制,但是沒有。