2011-11-25 60 views
2

我一直在重新組織一些代碼,並希望使用程序來驗證diff是否只包含匹配的添加和刪除對。我使用git作爲源代碼控制,希望有一些內置到git中的東西可以爲我做到這一點?這也將是非常有用的,如果它能夠總結了要麼出現或dissapeared線驗證修補程序只包含移動


有誰知道,如果有這樣的工具嗎?

+0

只有當我們知道哪些行被移動時才能完成檢測,因此這可能是以下情況的重複:http://stackoverflow.com/questions/1380333/highlighting-added-deleted-lines-ignoring-moves-in-a -patch-file,它會要求忽略移動的行。 –

回答

1

正如prusswan所說 - 我認爲目前沒有工具存在。但是git可以檢測重命名,並且不應該很難檢測到對文件的更改。 -M選項也可以嘗試檢測重命名,而不僅僅是執行刪除/添加比較。

git diff -M 18b5850a07bb 
diff --git a/G b/G 
index e69de29..d0a432b 100644 
--- a/G 
+++ b/G 
@@ -0,0 +1 @@ 
+This is a change 
diff --git a/A b/H 
similarity index 100% 
rename from A 
rename to H 
diff --git a/B b/I 
similarity index 100% 
rename from B 
rename to I 
diff --git a/C b/J 
similarity index 100% 
rename from C 
rename to J 
diff --git a/D b/K 
similarity index 100% 
rename from D 
rename to K 
diff --git a/E b/L 
similarity index 100% 
rename from E 
rename to L 
diff --git a/F b/M 
similarity index 100% 
rename from F 
rename to M 
1

不知道這樣的工具,雖然它確實是一個有用的功能。在窗口上,您可以使用已移動線條檢測的WinMerge。否則,這related question可能會有所幫助。

1

你沒有說你正在處理什麼計算機語言。

我們的SmartDifferencer工具家族可能會提供幫助。這些工具比較編程語言的語法,以確定程序員操作(複製,移動,重命名 - 標識符 - 塊)解釋的術語差異,而不是行編輯操作。

如果您的文件中的編輯實際上只是整個編程結構的移動,SmartDifferencer可能會完全告訴您。

+0

嗨,我正在使用Java。我沒有提到這一點,因爲我沒有考慮過可能存在語言特定工具的想法。謝謝你的提示! –

1

另一種方法將是一個視覺之一,可能在GIT 2.14.x/2.15(Q3 2017),因爲「git diff」已被教導以可選地油漆新線是 相同刪除的行從真正別處不同新的 行

換句話說:用於專用顏色移動

參見commit 61e89eacommit 86b452ecommit 176841fcommit 2e2d5accommit e6e045fcommit 146fdb0commit 30b7e1ecommit bd03329commit 0911c47commit 4eed0ebcommit f359713commit 5af6ea9commit 4acaaa7commit a29b0a1commit 3ee8b7bcommit f2bb121commit ff95867,commit 091f8e2,commit b9cbfde,commit 68abc6f(2017年6月30日)作者:Stefan Beller (stefanbeller)
(在commit b6c4058Junio C Hamano -- gitster --合併8月27日2017)

git config documentation now includes

diff.colorMoved 

如果設置爲一個有效的<mode>或一個真值,移動在一個diff線被着色不同的是,有效模式see '--color-moved' in git-diff的細節。
如果只設置爲true,將使用默認的顏色模式。
設置爲false時,移動的線條不會着色。

欲瞭解更多信息,請參閱commit 2e2d5ac