git commit -a不应该绕过git hook [英] git commit -a bypasses git hook when it shouldn't

查看:93
本文介绍了git commit -a不应该绕过git hook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个commit-msg的git钩子,当我运行时,它工作得很愉快

I have a git hook for commit-msg which works quite happily when I run

git commit -m "MSG HERE"

但是如果我跑步

git commit -a

使用文本编辑器触发提交的操作会跳过钩子.

Which triggers committing using your text editor it skips the hook.

关于如何解决此问题的任何建议?

Any suggestions on how to fix this?

我的钩子如下

#!/bin/bash
if ! egrep -q 'DAVE-[0-9]+' $1 ; then
     echo "No Jira Issue Number found" >&2
     exit 1
fi

if [[ "$(wc -c $1 | awk '{print $1}')" -le 20 ]] ; then
     echo "Commit message too short" >&2
     exit 1
fi

推荐答案

我无法重现您的问题,所以我的猜测是存在误解-commit-msg挂钩在之后运行您指定了您的信息,即.关闭提交文本编辑器之后(而不是之前),因此您只会注意到git log中的更改.

I can't reproduce your problem, so my guess here is that there's a misunderstanding -- the commit-msg hook runs after you specified your message, ie. after you close the commit text editor, not before, so you will only notice the changes in your git log.

确定不计算注释行吗?这些将很容易将消息扩展到20个以上的字符.使用类似cat $1|grep -vE '^#'|wc -c|awk ...的东西.

Are you sure you're not counting comment lines? These would easily blow up the message to above 20 characters. Use something like cat $1|grep -vE '^#'|wc -c|awk ....

这篇关于git commit -a不应该绕过git hook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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