我如何在Git中编写预合并钩子? [英] How would I write a pre-merge hook in Git?

查看:324
本文介绍了我如何在Git中编写预合并钩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题说明了一切。有没有办法在合并之前执行操作?我猜测有一种方法可以使用 pre-commit 钩子,但我不太确定。

解决方案

您可以尝试使用 prepare-commit-msg 钩子。如果提交是合并或 .git / MERGE_MSG 文件存在,则第二个参数将为 merge 。非零退出状态将中止提交。



我认为这不适用于快进合并,因为不会有提交消息。



更多关于钩子的信息: https://www.kernel.org/pub/software/scm/git/docs/githooks.html#_prepare_commit_msg


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 sure.

解决方案

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

这篇关于我如何在Git中编写预合并钩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆