Git post commit: skip --amend and rebase

跟風遠走 提交于 2019-12-03 13:00:41

When rebasing, there's a directory called rebase-merge present in the .git folder. That could be an approach to disable the hook during a rebase (the start of a rebase btw is indicated by the pre-rebase hook).

Regarding the --amend however, I can't help you.

If you want to detect git commit --amend from a hook, this is your best option

bash

if [[ $(ps -ocommand= -p $PPID) == "git commit --amend" ]]; then
    echo "always allow git commit --amend"
    exit 0
fi

ruby

parent=`ps -ocommand= -p #{Process.ppid}`.chomp
if parent == "git commit --amend"
  # Always allow an amend
  puts "always allow git commit --amend"
  exit 0
end

git and shell aliases are expanded in the shell output, so this covers those cases too

Inspiration: https://github.com/brigade/overcommit/issues/146

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!