For the trunk "master" I can do "git reset hard" to an earlier commit and then "git push force", to rewrite it in the repository. And I lose part of the development, after this commit. But if for some branches it is not so critical, then for the trunk "master" is very critical. Is it possible to disable do "push force", which overwrite "master" trunk of repository, and how can I switch off it?
我遇到过的每个分支禁用强制推送的唯一方法是使用预接收挂钩,如https://github.com/olshanov/git-hooks/blob/master/pre-receive所示..deny-force-push-to-branches(我没有写这个钩子,但它很有用).
关键部分是
while read oldrev newrev ref ; do
# old revision is blank - branch creation
if [ "$oldrev" = "0000000000000000000000000000000000000000" ] ||
# new revision is blank - branch deletion
[ "$newrev" = "0000000000000000000000000000000000000000" ] ||
# branch != master - pass through
[ "$ref" != "refs/heads/master" ] ;
then
# create new or delete old branch
# or force pushing to non-master branch
continue;
fi
base=$(git merge-base $oldrev $newrev);
if [ "$base" != "$oldrev" ] ; then
# non fast forward merge
echo "Force pushing of $ref is forbidden to master";
exit 1;
fi
done
exit 0;
Run Code Online (Sandbox Code Playgroud)
这仍然允许您删除/创建主分支并强制推送到其他分支,但会阻止您强制推送到主分支本身.
可以通过设置全局禁用强制推动
但这会为每个分支关闭它们
| 归档时间: |
|
| 查看次数: |
3283 次 |
| 最近记录: |