I'm trying to add a custom merge strategy similar to the one in this question: Git merge conflict to always take the newest file
I've saved the script as git-merge-latest.sh
and added the following lines to .git/config
:
[merge "latest"]
name = select latest file merge driver
driver = git-merge-latest.sh %O %A %B
However, when I run git pull --strategy latest
, I get the message:
Could not find merge strategy 'latest'.
Available strategies are: octopus ours recursive resolve subtree.
I've tried checking git config merge.latest.driver
, which returns the expected output. I also changed the value of driver
to true
just to verify that it wasn't a problem with finding the script.
This happens on two different systems running git 1.8.2.2 and 1.7.9.5. What am I doing wrong?
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.
Git's new merge-ort strategy is a scratch rewrite of its recursive strategy but addresses correctness and performance problems. GitHub reports merge-ort can be as much as a "500x" speed-up for large merges with many renames. Merge-ort for merges in a re-base operation can be a speed-up of over 9000x.
Using git rebase Instead of git merge. Using the "git merge" command is probably the easiest way to integrate changes from one branch into another. However, it's not your only option: "git rebase" offers another, slightly different way of integration.
In this case, you didn't configure a merge strategy, you configured a merge driver:
A merge strategy is a program that determines how two (or more) commits are merged. By default, git merge
uses the "recursive" strategy, found in the program git-merge-recursive
. By specifying the --strategy <strategy>
flag to git-merge
(or git-pull
) you tell it to invoke a different strategy. If you want to plug in your own merge strategy, you can, by creating an executable git-merge-mystrategy
in your path and running git merge --strategy mystrategy
.
This is different than a merge driver. A merge driver is the mechanism used to resolve a conflict on a file that exists when merging two commits. You plug in your own merge driver in the manner you outlined, by configuring a merge.mydriver.driver
setting.
To enable your merge driver for a particular file, you need to configure the driver for that file in .gitattributes
:
filename merge=mydriver
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