2

I have been reorganizing some code and would like to use a program to verify that the diff consists of only matching pairs of additions and deletions. I am using git as source control so hopefully there is something built into git that can do this for me? It would also be very useful if it could summarize lines that have either appeared or dissapeared


Does anybody know if there is such a tool?

prusswan
  • 6,853
  • 4
  • 40
  • 61
Ben Page
  • 3,011
  • 4
  • 35
  • 37
  • Detection can only be done if we know which lines moved, so this is probably a duplicate of: http://stackoverflow.com/questions/1380333/highlighting-added-deleted-lines-ignoring-moves-in-a-patch-file , which asks to ignore the moved lines. – Ciro Santilli OurBigBook.com Feb 15 '14 at 10:44

4 Answers4

1

Another approach would be a visual one, possible with Git 2.14.x/2.15 (Q3 2017), since "git diff" has been taught to optionally paint new lines that are the same as deleted lines elsewhere differently from genuinely new lines.

In other words: dedicated color for moved lines

See commit 61e89ea, commit 86b452e, commit 176841f, commit 2e2d5ac, commit e6e045f, commit 146fdb0, commit 30b7e1e, commit bd03329, commit 0911c47, commit 4eed0eb, commit f359713, commit 5af6ea9, commit 4acaaa7, commit a29b0a1, commit 3ee8b7b, commit f2bb121, commit ff95867, commit 091f8e2, commit b9cbfde, commit 68abc6f (30 Jun 2017) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit b6c4058, 27 Aug 2017)

The git config documentation now includes:

diff.colorMoved

If set to either a valid <mode> or a true value, moved lines in a diff are colored differently, for details of valid modes see '--color-moved' in git-diff.
If simply set to true, the default color mode will be used.
When set to false, moved lines are not colored.

For more, see commit 2e2d5ac.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Not aware of such a tool although it is indeed a useful feature. On windows you can use WinMerge which has moved lines detection. Otherwise, this related question may be helpful.

Community
  • 1
  • 1
prusswan
  • 6,853
  • 4
  • 40
  • 61
1

As prusswan says - I do not think a tool exists currently. But git can detect renames and it should not be hard to detect changes to a file. The -M option also git to try and detect renames rather than just doing a delete/add diff.

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
Adrian Cornish
  • 23,227
  • 13
  • 61
  • 77
1

You didn't say what computer language(s) you were handling.

Our SmartDifferencer family of tools might be able to help. These tool compare the syntax of a programming language to determine difference in terms explainable by programmer actions (copy, move, rename-identifier-in-block) rather than line editing actions.

If the edits in your files are really just moves of entire programming constructs, SmartDifferencer will likely tell you exactly that.

Ira Baxter
  • 93,541
  • 22
  • 172
  • 341
  • Hi Ira, I am using Java. I didn't mention that because I hadn't considered the idea language specific tools might exist. Thanks for the tip! – Ben Page Nov 28 '11 at 15:40