I sometimes edit xml-like files, like plist
s or xib
s, and sometimes i get diffs like .
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.
Asked
Active
Viewed 1,368 times
9
-
Are there differences in the whitespace? – Paul Cezanne Oct 08 '15 at 14:23
-
1no. especially in the xml style files, because they are generated by tools. – pvinis Oct 08 '15 at 14:27
-
1Drat, I had hoped it was that easy for you... – Paul Cezanne Oct 08 '15 at 18:38
1 Answers
6
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:
-
1I 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
-
-
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