gitmergeconflictautomerge

Let git merge different filetypes with an external tool?


we are working on a project where we often get the same conflict due to git not able to merge the files correctly. However these conflicts can be easily fixed with an external script. Is it somehow possible to let git now that it always should handle merge conflicts on a file with a specific extension with an external script? The script needs the >>>> and <<<< markers from git to find the changed parts in the file, so git should call our script after it is done with it's own merge.

Does anybody know if there is a hook we could use for that or maybe you can tell git to run this script for conflicts in a specified file?

Best regards, Michael


Solution

  • If the merge conflict resolution is always the same, check out git rerere.
    It is described in "Rerere Your Boat..." and in "gitster's journal - Fun with rerere"

    The name stands for "reuse recorded resolution" and as the name implies, it allows you to ask Git to remember how you've resolved a hunk conflict so that the next time it sees the same conflict, Git can automatically resolve it for you.

    You will need to activate it though:

    git config --global rerere.enabled 1