10

我有一个 post-commit 钩子,它在 ruby​​ 中做一些事情。它工作得很好,但在某些情况下,我想在执行git rebaseor时跳过代码执行git commit --amend

有人知道在这些情况下我如何无法触发提交后挂钩或任何解决方法吗?

4

2 回答 2

7

变基时,文件夹中有一个名为rebase-mergepresent 的.git目录。这可能是一种在 a 期间禁用钩子的方法( btwrebase的开始由钩子指示)。rebasepre-rebase

但是--amend,我帮不了你。

于 2012-07-06T18:55:36.540 回答
1

如果你想从钩子中检测 git commit --amend ,这是你最好的选择

重击

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

红宝石

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 和 shell 别名在 shell 输出中扩展,所以这也涵盖了这些情况

灵感:https ://github.com/brigade/overcommit/issues/146

于 2018-03-28T13:00:39.140 回答