pvinis
pvinis

Reputation: 4139

how can I avoid weird git diffs like this?

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.

Upvotes: 9

Views: 1616

Answers (1)

sergej
sergej

Reputation: 17999

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:

Upvotes: 6

Related Questions