Git merge strategies vs. merge drivers vs. mergetools

37 Views Asked by At

Both Stack Overflow answers, and various webpages, give contradictory or conflicting definitions of "merge strategy", "merge driver", and "mergetool". Here is my best understanding of them.

  • merge strategy: called on every file that is merged; however, if two of {parent1,parent2,base} are the same, then the "low-level merge driver" (i.e., git merge-file) is never called. The merge strategy is responsible for detecting and handling renames. A merge strategy is hard to write. If you have a git-merge-xyz in your path then git will run it if you git merge --strategy xyz. The git-merge-xyz programs that come with git are just links to the git executable itself. You can supply multiple strategies: git merge will take the first that succeeds (0 exit status) or will heuristically choose among the strategies whose exit status is 1. When writing a merge strategy use GIT_TRACE=1 git merge -s <strategy> to see the command-line arguments passed to it. There are also environment variables that have effects.
  • merge driver: called automatically when there is a difference in file content (no two of {base,parent1,parent2} are the same). It is run once per file with a conflict. It is run on temporary files, but you can get the path of the conflicting file using the %P parameter. It observes the original version of the parent and base files. It overwrites its input named %A with the merge result, which may contain conflict markers. You can use Git attributes to use different merge strategies for files whose names match given patterns.
  • mergetool (merge tool): never run automatically. If a user runs git mergetool, the mergetool is run on all conflicted files (one at a time) and observes the conflict markers. It gets the names of the original files.

A git mergetool is not invoked on files that contain no merge conflict. It assumes that if the git merge strategy didn't output a merge conflict, then the merge was correct. This means that a git mergetool will never reduce the number of clean-but-incorrect merges. It will only change some conflicted merges into correct or incorrect merges.

A git merge driver is never called if two of {base,parent1,parent2} are the same.

My question is: are the above definitions and facts correct? Do they omit any important information?

0

There are 0 best solutions below