20

I've seen many blog posts and stack overflow posts say that git config --global diff.algorithm patience will allow both diffs and merges to use the patience strategy option with the default recursive algorithm.

I have found this to not be the case, and I pose the following demo to show why not.

git config --global diff.algorithm patience   //mythical config statement  

git clone https://github.com/kjlubick/PracticingGit.git
cd PracticingGit
git checkout origin/patience-merge-1 -t

git checkout -b merge_test           //temp branch for merging
git diff origin/patience-merge-2

image This diff (image courtesy of meld looks pretty good. Let's try to merge it in.

git merge origin/patience-merge-2

image

Huh? That merge looks ugly. Despite lines 9-19 not actually changing, they are marked as conflicted/changed in completely different way than with the diff.

If we force the merge to use the patience strategy option:

git merge --abort
git merge origin/patience-merge-2 -X patience

image

That's much better. The conflicts match up with the diff we made earlier and are semantically correct.

How can I make merging actually use the patience setting, not just diffs?

Additional shots in the dark I tried (unsuccessfully):

git config --global merge.algorithm patience
git config --global merge.diff.algorithm patience

System info:
Windows 8.1
git version 1.8.4.msysgit.0 (via GitHub for Windows 2.0)

Zecong Hu
  • 2,584
  • 18
  • 33
KevinL
  • 1,238
  • 11
  • 28
  • The man page says this for the `-s` option: `Use the given merge strategy; can be supplied more than once to specify them in the order they should be tried. If there is no -s option, a built-in list of strategies is used instead (git merge-recursive when merging a single head, git merge-octopus otherwise).` This sounds like making this the default behavior is unlikely to be possible. – Chris Hayes Aug 03 '14 at 01:47
  • So perhaps it may be impossible via `git config`, but what about workarounds? Is there another way? – KevinL Aug 06 '14 at 15:02
  • Possible duplicate of [How to set patience as default git diff algorithm](http://stackoverflow.com/questions/4460202/how-to-set-patience-as-default-git-diff-algorithm) – notbad.jpeg Aug 11 '16 at 14:48

3 Answers3

9

Patching git, like Appleman1234 is not ideal. I hope this feature comes in future versions.

For now, I think I'll have to settle for the alias

git config --global alias.pmerge "merge -X patience --"

which allows me to do

git pmerge origin/patience-merge-2

instead of

git merge origin/patience-merge-2 -X patience

in the example I gave earlier.

KevinL
  • 1,238
  • 11
  • 28
2

There is a config item for branch-specific merge options,

git config branch.master.mergeoptions "-X patience"

but not a global default setting.

jthill
  • 55,082
  • 5
  • 77
  • 137
0

One way would be to patch git to add the functionality you are asking for.

An example untested, uncompiled patch to builtin/merge.c is

diff -Nar merge.c merge.c-new 
77c77
< static const char *pull_twohead, *pull_octopus;
---
> static const char *pull_twohead, *pull_octopus,*diff_algorithm;
586a587,588
>       else if (!strcmp(k, "diff.algorithm"))
>               return git_config_string(&diff_algorithm, k, v);
1305a1308,1311
>               int diff_algorithm_mask = 0;
>               if (diff_algorithm != null){
>                       diff_algorithm_mask = parse_algorithm_value(diff_algorithm);
>               }
1308a1315,1317
>                       if (diff_algorithm != null){
>                               add_strategies(diff_algorithm,diff_algorithm_mask);
>                       }
1310a1320,1322
>                       if (diff_algorithm != null){
>                               add_strategies(diff_algorithm,diff_algorithm_mask);
>                       }

Note that , I believe if a patch like this was to get be included in git, there would probably have to be additional work to add a configuration value which enables and disables this behaviour as the documentation clearly states that changing that value only changes the diff algorithm. An alternative to this is add a configuration variable merge.algorithm and have it do the default logic if unset and the algorithm in merge.algorithm if set.

Another alternative that doesn't require code changes is shell aliasing git commands.

Appleman1234
  • 15,946
  • 45
  • 67
  • Code changes are not ideal. I think I'll have to settle for the alias `git config --global alias.pmerge "merge -X patience --"` – KevinL Aug 10 '14 at 03:15