6

I sometimes edit xml-like files, like plists or xibs, and sometimes i get diffs like this one. Instead of the diff starting with the <dict> and ending with the </dict>, it starts and ends +2 lines. This also happens sometimes with Objective-C code too. I would add a new case in a switch, and the diff will not start from case down to break, but it will again have an offset of one or two lines.
I understand that this happens because the previous and next lines are basically the same, but is there a way I can avoid this, fix this, or change its behavior in some way? Thanks.

rmaddy
  • 298,130
  • 40
  • 468
  • 517
pvinis
  • 3,855
  • 5
  • 33
  • 55

1 Answers1

5

Try another diff algorithm. I had good results with the patience algorithm in cases like this.

Use for example:

git diff --patience

From the git-diff manual:

--patience

Generate a diff using the "patience diff" algorithm.

--diff-algorithm={patience|minimal|histogram|myers}

Choose a diff algorithm. The variants are as follows:

default, myers

The basic greedy diff algorithm. Currently, this is the default.

minimal

Spend extra time to make sure the smallest possible diff is produced.

patience

Use "patience diff" algorithm when generating patches.

histogram

This algorithm extends the patience algorithm to "support low-occurrence common elements".


Related:

Community
  • 1
  • 1
sergej
  • 14,042
  • 6
  • 38
  • 75
  • I read about it, and the comparisons etc. though when applying it on my change above, I still get the same diff. – pvinis Oct 09 '15 at 08:05
  • @pvinis Could you provide the two files? – sergej Oct 09 '15 at 11:54
  • old file: http://pastebin.com/raw.php?i=C6B3F6n9 new file: http://pastebin.com/raw.php?i=qPG5zCbQ change: http://pastebin.com/raw.php?i=tpV1tUur – pvinis Oct 09 '15 at 13:23