How to detect commit --amend by pre-commit hook ?

后端 未结 5 1281
陌清茗
陌清茗 2021-02-19 07:09

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 a

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-19 07:23

    Another way to check if this is an --amend case, in standard shell:

    git_command=$(ps -ocommand= -p $PPID)
    if [ -z "${git_command##git\ commit*--amend*}" ]; then
        echo "The original command was a: git commit --amend"
        exit 0
    fi
    

提交回复
热议问题