GIT - 如何使分支与主分支相同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29796127/
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
GIT - How to make a branch be the same as master
提问by steveking198
I have a website using git
我有一个使用 git 的网站
The setup has the master branch as the live site and a develop branch as the dev domain which is used for testing features before they go live
该设置将主分支作为实时站点,将开发分支作为开发域,用于在功能上线之前进行测试
No work is ever done directly on master or develop, it's always done on feature branches and then merged in to develop for testing, followed by master to go live
从来没有直接在 master 或 develop 上完成任何工作,它总是在功能分支上完成,然后合并到 develop 进行测试,然后 master 上线
My issue is that I have one site which has had a lot of work merged in to the develop branch which is never going to go live
我的问题是我有一个站点,其中有很多工作合并到了永远不会上线的开发分支
I've been asked to make the develop branch match the master branch to ensure the work that's never going live doesn't affect the testing of other new features that get merged in to develop
我被要求使开发分支与主分支匹配,以确保永远不会上线的工作不会影响合并到开发中的其他新功能的测试
I've done a bit of research and from my understanding, I can't use rebase as that's more for updating a branch with commits made since you branched off
我已经做了一些研究,根据我的理解,我不能使用 rebase,因为它更多地用于更新分支,因为你分支后所做的提交
The only option that seems to do what I need is to rename the develop branch and then recreate it from master and force a push to update it remotely
似乎做我需要做的唯一选择是重命名开发分支,然后从 master 重新创建它并强制推送远程更新它
Is this my best option? Or is there another way I don't know about? Or maybe rebase is correct but I'm not quite understanding its purpose?
这是我最好的选择吗?或者还有其他我不知道的方法吗?或者 rebase 是正确的,但我不太了解它的目的?
Thanks in advance
提前致谢
回答by pmr
If you don't care about preserving develop just checkout develop
and reset it to master
.
如果您不关心保留开发只需结帐develop
并将其重置为master
.
# make sure master is up to date before you do this
git checkout develop
git reset --hard master
git push -f # force push the branch
This is often done for an integration
branch every morning, so that the nightly integration is always based on master.
这通常integration
每天早上为一个分支完成,因此每晚的集成总是基于 master。