I'd like to use Git's patience diff algorithm (the one you get if you invoke git diff
with the --patience
argument) with git add -p
. How can I do this?
Background: I'm working with some XML files, and git diff
's normal algorithm produces pretty poor diffs due to "misaligned" entry/exit tags. If I run git diff --patience
, I get much more useful diffs, but there's no obvious way to use these diffs in git add -p
.
The first thing to note is that patience diff is not a diff algorithm in and of itself. What it really is is a method of matching up lines in two versions of a document in order to break them into smaller pieces, before using an actual diff algorithm like Myers on those pieces.
Myers Algorithm – human readable diffs This is used by tools such as Git Diff and GNU Diff.
The essence of diff algorithms is in contrasting the two sequences and to receive insight of the transformation from the first into the second by a series of operations using the ordered deletion and insertion. The subsequence can be flagged as a change if a delete and an insert concur on the same scope.
git add -p
currently rejects diff flags, but you can use the diff.algorithm
config option:
git config --global diff.algorithm patience
New in Git 1.8.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With