【问题标题】:Check if commit is first commit in pre-commit hook检查提交是否是预提交钩子中的第一次提交
【发布时间】:2012-06-02 20:54:30
【问题描述】:

目前我正在使用 pre-commit 挂钩来禁止提交到主分支(迫使我在其他分支上工作并合并更改)。这不允许我对新创建的存储库进行初始提交。如果是第一次提交,我想添加一个检查以允许在 master 上提交。

我已经尝试了多个版本,但都没有运气......

if [[ `git shortlog | grep -E '^[ ]+\w+' | wc -l | tr -d ' '` == 0 -a `git symbolic-ref HEAD` == "refs/heads/master" ]]
then
    echo "You cannot commit in master!"
    echo "Stash your changes and apply them to another branch"
    echo "git stash"
    echo "git checkout branch"
    echo "git stash apply"
    exit 1
fi

【问题讨论】:

    标签: git githooks pre-commit-hook


    【解决方案1】:

    只是执行

    git commit --no-verify ...
    

    第一次提交。然后你的预提交钩子可以简单地应用于主分支。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-11
      • 1970-01-01
      • 2018-01-07
      • 2022-01-07
      • 2015-03-04
      • 2013-12-15
      相关资源
      最近更新 更多