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

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

问题描述

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

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.

推荐答案

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

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.

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

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

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