【问题标题】:Git post commit: skip --amend and rebaseGit post commit:跳过 --amend 和 rebase
【发布时间】:2012-07-07 05:43:10
【问题描述】:

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

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

【问题讨论】:

  • 我无法让这个钩子与git commit --amend 一起运行,而且我很有信心它从来没有发生在我身上。我很想知道这对您来说是否仍然是一个问题,以及在什么情况下会发生这种情况?

标签: git githooks post-commit-hook


【解决方案1】:

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

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

【讨论】:

  • 你的意思是检测文件夹的存在或类似的东西?
  • 是的。对 ruby​​ 的了解不足以举一个例子,但是当你的 post-commit 钩子被调用时,你当然也可以在 ruby​​ 中检查是否有一个名为 ../rebase-merge 的文件夹(相对于钩子目录)
【解决方案2】:

如果你想从钩子中检测 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-15
    • 2017-05-11
    • 1970-01-01
    • 2011-07-15
    • 1970-01-01
    • 2022-12-15
    • 2010-11-30
    • 1970-01-01
    相关资源
    最近更新 更多