有没有办法使本地分支不变? [英] Is there a way to make a local branch immutable?
问题描述
我非常愚蠢,有时我会在错误的 master
分支中合并一个功能分支,而不是 develop
分支,这当然会导致痛苦和痛苦。
I'm extremely stupid and sometimes I merge a "feature branch" in the wrong master
branch as opposed to the develop
branch and that of course leads to pain and suffering.
由于这已经是第二次了,我想知道是否有办法
Since it's the second time already that this has been happening, I wonder if there's a way for me to make a branch immutable locally.
我已经尝试过这个预提交钩子是为了防止我直接在所述分支上进行提交,但这并不是像下面那样停止合并:
I've already tried with this pre-commit hook to prevent me from directly making commits on said branch, but this is not stopping merges as in:
git checkout master
git merge wip
有没有办法防止对本地分支机构的所有可能更改?如果不是,那么是否至少有可能防止更改被推送?
Is there a way to prevent all possible changes to a local branch? If not, is it at least possible to prevent changes from being pushed?
推荐答案
您不能使本地分支不可变(存在没有在合并操作之前运行的本地挂钩)。但是,如果您不打算在分支上进行提交,请不要签出。如果已将其签出,请删除本地分支:
You cannot make a local branch immutable (there is no local hook that runs before a merge operation). However, if you're not going to be making commits on the branch, just don't check it out. If you have it checked out already, delete the local branch:
$ git checkout some-other-branch
$ git branch -D master
现在,当您尝试签出 master时
分支将失败:
Now when you attempt to checkout the master
branch it will fail:
$ git checkout master
error: pathspec 'master' did not match any file(s) known to git.
如果您需要引用上游 master
分支(例如,对于 diff
),您可以直接引用它:
If you ever need to refer to the upstream master
branch (e.g., for a diff
), you can just refer to it directly:
$ git diff origin/master
这篇关于有没有办法使本地分支不变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!