Use Git's patience diff algorithm for interactive add
Question
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
.
Solution
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.
OTHER TIPS
This worked for me:
git -c diff.algorithm=patience add -p [...]
I am running the latest git v2.1.0 in Cygwin.
Hmmmm... One thing you could do is pipe the output of git diff
to a temporary place, then read it back in with git apply
:
git diff --patience <commitA> <commitB> > /tmp/patch.out
# checkout a new branch or otherwise do what you need to prep
git apply < /tmp/patch.out
That'll apply the output of the diff to the working directory, but it won't commit or stage the changes. You can then run git add -p
as you normally would, and the --patience
diff will be the changes you're interactively adding.
There's no reason you couldn't pipe diff
to apply
directly, if it better suits your workflow. It's something I do fairly regularly when rebuilding my own local branches for production integration.
Looks like you can also use it as a merge strategy, so it might be the case that instead of interactively adding the diffs, you could simply create a branch with what you want, then merge it in.