当git commit-msg挂钩失败时,如何恢复提交消息? [英] How can I recover the commit message when the git commit-msg hook fails?

查看:305
本文介绍了当git commit-msg挂钩失败时,如何恢复提交消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用git的一个钩子commit-msg来验证某种格式和内容的提交消息.

I'm using one of git's hooks commit-msg to validate a commit message for certain format and contents.

但是,每当提交消息失败时,有时我的消息中就会丢失一段或更多的文本.

However, whenever a commit message fails the hook, I have sometimes lost a paragraph or more of text from my message.

我一直在尝试将其保存在某个地方,但是当用户尝试修复失败的提交消息时,我不知道如何将其还原给用户,只会显示最后一条正确的提交消息.

I've played around with saving it off somewhere, but I'm not sure how to restore it to the user when they attempt to fix the failed commit message, only the last good commit message shows up.

以前有人处理过吗?您是如何解决的?

Has anyone else dealt with this before? How did you solve it?

信息:我正在使用python脚本进行验证.

Info: I am using python scripts for my validation.

推荐答案

提交消息存储在.git/COMMIT_EDITMSG中.在失败"的提交尝试之后,您可以运行:

The commit message is stored in .git/COMMIT_EDITMSG. After a "failed" committing attempt, you could run:

git commit --edit --file=.git/COMMIT_EDITMSG

或更短,例如:

git commit -eF .git/COMMIT_EDITMSG

这将在您的$EDITOR(或在您的Git配置中设置的编辑器)中加载错误的提交消息,以便您可以尝试修复该提交消息.您还可以使用以下方法为上述设置别名:

which will load the bad commit message in your $EDITOR (or the editor you set up in your Git configuration), so that you can try to fix the commit message. You could also set up an alias for the above, with:

git config --global alias.fix-commit 'commit --edit --file=.git/COMMIT_EDITMSG'

,然后改用git fix-commit.

这篇关于当git commit-msg挂钩失败时,如何恢复提交消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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