How would I write a pre-merge hook in Git?

前端 未结 3 1141
终归单人心
终归单人心 2020-12-01 07:34

The question says it all. Is there a way to perform an action before a merge? I\'m guessing there\'s a way to make use of a pre-commit hook, but I\'m not quite

3条回答
  •  不思量自难忘°
    2020-12-01 08:05

    You can try using the prepare-commit-msg hook. The second argument will be merge "if the commit is a merge or a .git/MERGE_MSG file exists". A non-zero exit status will abort the commit.

    I don't think this will work with a fast-forward merge, since there won't be a commit message.

    More info on hooks: https://www.kernel.org/pub/software/scm/git/docs/githooks.html#_prepare_commit_msg

提交回复
热议问题