我怎样才能阻止自己在Git的主分支? [英] How can I stop myself from committing to the master branch in git?

查看:157
本文介绍了我怎样才能阻止自己在Git的主分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理想的工作流程是将变更提交到 dev ,并且只通过合并变更到master。git merge --no-ff dev

开启

  dev:git add。 
dev:git commit -m治愈癌症。
dev:git checkout master
master:git merge --no-ff dev



<

  master:git commit -a -m做了些惊人的事情 

只会承诺主人。如果我很幸运,我会马上意识到这一点,但如果我不这样做,我可以在上游再推上10个变化。所以这最终在远程:

 主人--------合并---提交 - 提交--- ------------合并
Dev \ Commit / \ commit - commit /

虽然它看起来应该是这样的:

 主人--------合并 - ----------- Merge --------------------- Merge 
Dev \ Commit / \ commit commit / \提交 - 提交 - 提交/

如何删除人为因素(即我的愚蠢)并阻止自己从提交到主分支?我在Ubuntu上。

解决方案

你可以很容易地写一个 pre-commit hook 检查你当前的分支,并根据分支名称拒绝提交。


My ideal workflow would be to commit changes onto dev and only merge changes to master via git merge --no-ff dev, but occassionaly what happens is:

On dev

dev: git add .
dev: git commit -m "Cured cancer."
dev: git checkout master
master: git merge --no-ff dev

Writes some more code

master: git commit -a -m "Did something amazing"

Whops, just committed to master. If I'm lucky I realize it right away, but if I don't I can push the branch upstream with another 10 changes on top. So this ends up in remote:

Master   -------- Merge --- commit - commit --------------- Merge
Dev      \ Commit/                        \ commit - commit /

While it should look like this:

Master   -------- Merge ------------- Merge --------------------- Merge
Dev      \ Commit/     \ commit commit /  \ commit - commit - commit /

How can I remove the human factor (i.e. my stupidity) and stop myself from committing to the master branch? I'm on Ubuntu.

解决方案

You could pretty easily write a pre-commit hook to check your current branch and reject the commit based on the branch name.

这篇关于我怎样才能阻止自己在Git的主分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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