1

目前我正在使用 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
4

1 回答 1

2

只执行

git commit --no-verify ...

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

于 2012-06-02T21:14:48.413 回答