Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting default diff algorithm does not translate to default merge algorithm (patience)

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)

like image 799
KevinL Avatar asked Jul 31 '14 15:07

KevinL


People also ask

What is the default git merge strategy?

Recursive is the default merge strategy when pulling or merging one branch. Additionally this can detect and handle merges involving renames, but currently cannot make use of detected copies. This is the default merge strategy when pulling or merging one branch.

What algorithm does git diff use?

Myers. Myers algorithm was developed by Myers (1986). In the git diff command, this algorithm is used as the default. The operation of this algorithm traces the two primary identical sequences recursively with the least edited script.

What is the ORT strategy?

ort. This is the default merge strategy when pulling or merging one branch. This strategy can only resolve two heads using a 3-way merge algorithm.

What is merge made by ORT strategy?

The merge-ort strategy is a from-scratch rewrite with the same concepts (recursion and rename-detection), but solving many of the long-standing correctness and performance problems. The result is much faster. For a merge (but a large, tricky one containing many renames), merge-ort gains over a 500x speedup.

What is diffing algorithm in react?

What is Diffing Algorithm ? React uses virtual DOM which is a lightweight version of the DOM. The only difference is the ability to write the screen like the real DOM, in fact, a new virtual DOM is created after every re-render. DOM stores the components of a website in a tree structure.

What is the default merge strategy when pulling or merging?

This is the default merge strategy when pulling or merging more than one branch. This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches.

How does the merge algorithm work when a change is reverted?

The merge algorithm therefore considers the reverted change as no change at all, and substitutes the changed version instead.

What is the default merge strategy in Git?

This is the default merge strategy when pulling or merging more than one branch. This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches.


2 Answers

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.

like image 109
KevinL Avatar answered Nov 07 '22 07:11

KevinL


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

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

but not a global default setting.

like image 31
jthill Avatar answered Nov 07 '22 07:11

jthill