防止在当地分支提交 [英] Prevent commits in a local branch

查看:125
本文介绍了防止在当地分支提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地git树中,我从存储库中的master分支中提交了提交,但所有的开发都在不同的分支中完成,并且也推送到另一个分支。



我想避免错误并防止在本地主分支中发生意外提交,并且只允许提出请求(然后我将发展分支重新分配给更新后的主分支)。这可能吗?如何?

Customizing-Git-Git-Hooks> pre-commit hook

例如,将以下脚本放置为 .git / hooks / pre-commit

 #!/ bin / bash 
如果测试$(git rev-parse --abbrev-ref HEAD)=master;那么
回声不能提交给主人
出口1
fi

并将其设置为可执行文件

  chmod + x .git / hooks / pre-commit 


In my local git tree I pull commits from the "master" branch in the repository, but all development is done in a different branch, and pushed in a different branch too.

I would like to avoid mistakes and prevent accidental commits in my local "master" branch, and allow only pull requests (then I'd rebase the developement branch to the updated master). Is this possible? How?

解决方案

You can use a pre-commit hook.

For example, place the following script as .git/hooks/pre-commit:

#!/bin/bash
if test $(git rev-parse --abbrev-ref HEAD) = "master" ; then 
  echo "Cannot commit on master"
  exit 1
fi

And set it as executable

chmod +x .git/hooks/pre-commit

这篇关于防止在当地分支提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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