是否有可能禁用“推动力”,其重写“主”存储库的主干? [英] Is it possible to disable do "push force", which overwrite "master" trunk of repository?

查看:97
本文介绍了是否有可能禁用“推动力”,其重写“主”存储库的主干?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于主干主,我可以对先前的提交执行git reset hard,然后执行git push force,将其重写到存储库中。在这个提交之后,我失去了部分开发。
但是如果对于某些分支来说它并不那么重要,那么对于主这个主干来说非常关键。
是否有可能禁用push force,它会覆盖存储库的mastertrunk,以及如何关闭它?

解决方案

禁用我以前碰到的每个分支的强制推送的唯一方法是使用预接收钩子,如https://github.com/olshanov/git-hooks/blob/master/pre-receive.deny-force- push-to-branches (我没有写这个钩子,但它很有用)。



这个关键部分是

  while read oldrev newrev ref; 
#旧修订为空 - 分支创建
if [$ oldrev=00000000000000000000000000000000000000000000] ||
#新版本为空 - 分支删除
[$ newrev=0000000000000000000000000000000000000000] ||
#branch!= master - 通过
[$ ref!=refs / heads / master];
然后
#创建新的或删除旧的分支
#或强制推送到非主分支
continue;
fi

base = $(git merge-base $ oldrev $ newrev);
if [$ base!=$ oldrev];然后
#非快进合并
回声强制推送$ ref被禁止掌握;
出口1;
fi
完成
出口0;

这仍然允许您删除/创建主分支并强制推送到其他分支,但会阻止您从强制推送到主分支本身。



可以通过设置

    $来禁用强制推送b $ b
  • receive.denyNonFastForwards

  • receive.denyDeletes
    / b>

    关闭每个分支

    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?

    解决方案

    The only way to disable force push on a per branch basis that I've ever come across is with a pre-receive hook as shown at https://github.com/olshanov/git-hooks/blob/master/pre-receive.deny-force-push-to-branches (I didn't write this hook but it is useful).

    The key section of this is

    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;
    

    This will still allow you to delete / create master branch and force push to other branches but will prevent you from force pushing to the master branch itself.

    It is possible to disable force push globally by setting

    • receive.denyNonFastForwards
    • receive.denyDeletes

    but this turns them off for every branch

    这篇关于是否有可能禁用“推动力”,其重写“主”存储库的主干?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆