Links
Snippets
Defining a custom merge driver
Steps
- Define the merge driver in git config
- Set this as the merge driver for some file patterns via gitattributes
- Create the merge driver
Define the driver in git config
[merge "custom_merge_example_01"] name = "My custom merge driver example 01" # %A: current version # %O: ancestor version # %B: other branch version # must overwrite %A driver = /usr/local/chirayu/bin/custom_merge_example_01 recursive = text
List this in gitattributes
Either in .git/info/attributes
or .gitattributes
*/version merge=custom_merge_example_01
The driver itself – custom_merge_example_01
#!/usr/bin/env zsh CURRENT_FILE=$1 ANCESTOR_FILE=$2 REVISED_FILE=$3 # Figure out how to merge these / transform them in some way # # REQUIRED: Final merge result must be in $CURRENT_FILE # # It's probably simple to fallback to or follow up with # (after # your custom transformation) the "merge" tool to do the actual # merge. "merge" leaves behind conflict markers on conflicts and # returns an error code (we'll pass along that same code.) merge -A $CURRENT_FILE $ANCESTOR_FILE $REVISED_FILE exit $?