flooose
flooose

Reputation: 529

Git hook for merge conflicts

Is there a git hook I can use for merge conflicts? After a failed git merge, it would be great to be able to write a script that opens all files with conflicts in $EDITOR. Unfortunately the post-merge hook doesn't run if there are conflicts and from what I've seen in the githooks man page, there are no other applicable hooks.

I'm wondering if I've missed something, or if there are other alternatives short of aliasing 'git merge' to a function or something like that.

Thanks, Chris

Upvotes: 21

Views: 3900

Answers (2)

flooose
flooose

Reputation: 529

As suggested by Charles Bailey, the best way to do this is by customizing the mergetool. Using this guide, I came up with this simple way to have merge conflicts opened in my editor:

[merge]
  tool = emacs
[mergetool "emacs"]
  cmd = $editor \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"

Since Charles Bailey never answered how I should give him credit for this, I hope this is an appropriate way to finally close this question.

Upvotes: 2

binarycreations
binarycreations

Reputation: 3181

I think there maybe two ways, as mentioned you by floose you could edit your mergetool or perhaps you could create another alias using:

for i in $(git ls-files -u | cut -f 2 | sort -u); do $EDITOR $i; done

Upvotes: 0

Related Questions