冻结 Git 分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10996248/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Freezing a Git branch
提问by millie
Let's say I have a develop branch. I create a feature branch from this to develop a feature. Once the feature is developed, it is merged back into develop. Pretty much like shown here:
假设我有一个开发分支。我从中创建了一个功能分支来开发一个功能。一旦开发了功能,它就会合并回开发。非常像这里显示的:
Is there a way I can freeze the feature branch so that no further commits can be made to it?
有没有办法可以冻结功能分支,以便不再对其进行提交?
The reason for not outright deleting the branch is so that viewing the history can still show the feature branch and that if there needs to be a tweak made to the feature then it is possible for someone to create a new feature branch from the last commit of the previous feature.
不彻底删除分支的原因是,查看历史记录仍然可以显示功能分支,并且如果需要对功能进行调整,那么有人可以从最后一次提交创建一个新的功能分支上一个功能。
采纳答案by gjcamann
Christopher is right, tagging will help you do this. I recommend deleting the branch name too to make it a little harder for someone to checkout the branch and make edits.
Christopher 是对的,标记将帮助您做到这一点。我也建议删除分支名称,以使某人更难签出分支并进行编辑。
First, merge the branch into develop
首先,将分支合并到develop
git checkout develop
git merge --no-ff feature_1
Then checkout the branch
然后结帐分支
git checkout feature_1
Then create a tag, with a comment.
然后创建一个带有注释的标签。
git tag -a -m "Freezing a feature branch that fixes.." feature_1_frozen
Then delete the branch
然后删除分支
git checkout develop
git branch -d feature_1
After doing this, you won't be able to checkout the branch by name. Instead you'll be able to checkout the tag by name, this will put you into a detached head state which will deter changes to the code.
执行此操作后,您将无法按名称签出分支。相反,您将能够按名称签出标签,这将使您进入分离的头部状态,从而阻止对代码的更改。
Now to wrap things up and sync with origin...
现在总结一下并与原点同步......
Push the update and new tag
推送更新和新标签
git push --tags origin develop
Delete the remote feature branch
删除远程功能分支
git push origin :feature_1
回答by Christopher
Just tag it.
只需标记它。
git tag -a frozen -m "Feature branch frozen here."
git push <remote> frozen
Sure, someone could come along later and push to the branch, but the tag shouldn't change unless it's forcibly overrode. You could configure your remote to reject force pushes if you're concerned about it, or even sign the tags with a GPG key to ensure authenticity.
当然,有人可以稍后出现并推送到分支,但标签不应更改,除非它被强行覆盖。如果您担心,您可以将遥控器配置为拒绝强制推送,甚至可以使用 GPG 密钥对标签进行签名以确保真实性。
Getting the state of the feature branch when it was frozen is as simple as git checkout frozen
. Developers can branch from this point at will using one command: git checkout -B <new_branch> frozen
.
获取冻结时功能分支的状态就像git checkout frozen
. 开发人员可以使用一个命令从这一点随意分支:git checkout -B <new_branch> frozen
.
回答by Fatih Arslan
You could use something like gitoliteor gerritfor access controls and permission along branches, tags and repos.
您可以使用gitolite或gerrit 之类的东西来控制分支、标签和存储库的访问权限。
Have a look here:
看看这里:
回答by Philip Oakley
Consider git-freezeas mentioned in Git - Branch status (frozen, inactive, etc.).
考虑Git-Branch status (frozen, inactive, etc.) 中提到的git-freeze。
回答by BHUVANESH MOHANKUMAR
I am using the "Git Bash" console to freeze the branch:
我正在使用“Git Bash”控制台来冻结分支:
[Solution worked Best during Oct 2018]
[解决方案在 2018 年 10 月期间效果最佳]
Don't have Git Bash?
没有 Git Bash?
Here is how to install and use the Git Bash console:
以下是安装和使用 Git Bash 控制台的方法:
Reference:
参考:
https://github.com/msysgit/msysgit/releases/
https://github.com/msysgit/msysgit/releases/
https://help.github.com/articles/set-up-git/
https://help.github.com/articles/set-up-git/
How to freeze a branch
如何冻结分支
git checkout {branch-to-keep-alive}
git merge --no-ff {branch-to-freeze}
If git asks for a merge message, type it, then use [Esc] key then type ":wq" command to save and exit.
如果 git 要求合并消息,请输入它,然后使用 [Esc] 键然后输入“:wq”命令保存并退出。
You have to go to visual studio and make sure that you can build the solution successfully (with {branch-to-keep-alive}).
您必须去 Visual Studio 并确保您可以成功构建解决方案(使用 {branch-to-keep-alive})。
git checkout {branch-to-freeze}
git tag -a -m "{your-description}" {tag-for-the-branch-to-freeze}
Convention: create the tag like this: {branch-name}_frozen
约定:创建这样的标签:{branch-name}_frozen
git checkout {branch-to-keep-alive}
git branch -d {branch-to-freeze}
git push --tags origin {branch-to-keep-alive}
git push origin :{branch-to-freeze}
How to merge a branch with master:
如何将分支与 master 合并:
git checkout {your-working-branch}
Git merge master
Git合并大师
Open vs and resolve merge conflicts if there is any. Always rebuild the whole things.
打开 vs 并解决合并冲突(如果有)。总是重建整个事物。
git checkout master
git merge development
There won't be any conflicts now and everything is set to go.
现在不会有任何冲突,一切都将进行。
Git Bash Console:
Git Bash 控制台: