如何通过pre-commit钩子检测commit --amend? [英] How to detect commit --amend by pre-commit hook ?

查看:81
本文介绍了如何通过pre-commit钩子检测commit --amend?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我提交--amend时,如果该提交已经被推送到远程存储库,则这是不安全的提交.

When I do commit --amend, it is unsafe commit if the commit already has been pushed to remote repository.

我想检测不安全的提交-通过预提交钩子和中止进行修改.

I want to detect unsafe commit --amend by pre-commit hook and abort.

但是预提交钩子没有参数.我不知道如何检测--amend.

But pre-commit hook has no arguments. I don't know how to detect --amend.

我该怎么办?

推荐答案

在遵循@Roger Dueck的回答后,最终做了:

Following @Roger Dueck's answer, ended up doing:

#./.git/hooks/prepare-commit-msg

IS_AMEND=$(ps -ocommand= -p $PPID | grep -e '--amend');

if [ -n "$IS_AMEND" ]; then
  return;
fi

这篇关于如何通过pre-commit钩子检测commit --amend?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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