2

I'm trying to use git add --patch, and I noticed that it's diffs aren't the same as those generated using opendiff.

  1. Is this common? Are there different diff algorithms? Am I just nuts?
  2. Assuming the above is "yes", is there a way to force git to use the opendiff algorithm?
eykanal
  • 26,437
  • 19
  • 82
  • 113

1 Answers1

2

There are indeed different diff algorithms. (And there are many possible diffs that will result in exactly the same change to a file - this is one of the reasons it's so sensible that git doesn't store changes, it only stores the state of the tree at each commit :))

Even within git, for some commands you can choose between two different diff algorithms - for example, try moving a function in some C code and compare the output of:

git diff

... and:

git diff --patience

The latter is usually more readable, albeit slower to calculate.

I'm not sure what algorithm opendiff uses, but perhaps it's similar to patience diff?

Unfortunately, I don't believe that it is currently possible in git to use a different diff algorithm in git add -p, although I would find that very useful too. There is a patch series here to add that feature, but it seems as if the author hasn't sent that upstream yet.

Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327