Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I avoid weird git diffs like this?

Tags:

git

diff

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.

like image 738
pvinis Avatar asked Oct 08 '15 13:10

pvinis


People also ask

What are git diffs?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

In which situation should you use git diff?

The git diff command helps you see, compare, and understand changes in your project. You can use it in many different situations, e.g. to look at current changes in your working copy, past changes in commits, or even to compare branches.

Does git only store diffs?

Hashes and diffs If you then make changes, git will only need to store the changes (also called the diff), but it will also store the hash of the data.

What does ++ mean in git diff?

When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.


1 Answers

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:

  • How to set patience as default git diff algorithm
  • What is git diff --patience for?
like image 169
sergej Avatar answered Oct 14 '22 00:10

sergej