git 如何将develop分支重置为master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18436680/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:49:44  来源:igfitidea点击:

how to reset develop branch to master

gitversion-controlbranch

提问by trrrrrrm

I have develop& masterbranches, my developbranch is messy now and i would like to reset it and make it as a copy of my master. i'm not sure if merging the masterinto developwill make both of them identical. after trying to merge i got many conflicts i solved them using:

我有develop&master分支,我的develop分支现在很乱,我想重置它并将其作为我的master. 我不确定合并masterintodevelop是否会使它们完全相同。尝试合并后,我遇到了很多冲突,我使用以下方法解决了它们:

git checkout develop
git merge origin/master
//got many conflicts
git checkout . --theirs

is this enough for developbranch to be an identical copy to master?

这足以让developbranch 成为与 相同的副本master吗?

Thanks

谢谢

回答by Tim Jarvis

if you just want them to be the same thing

如果你只是希望它们是一样的

then

然后

//from Develop and assuming your master is up to date with origin/master
git reset --hard master

回答by Amber

If you want to make developbe identical to master, the simplest way is just to recreate the pointer:

如果要使develop与 相同master,最简单的方法就是重新创建指针:

git branch -f develop master

Or, if you already have developchecked out:

或者,如果您已经develop签出:

git reset --hard develop master

Note however that both of these options will get rid of any history that develophad which wasn't in master. If that isn't okay, you could preserve it by instead creating a commit that mirrored master's latest state:

但是请注意,这两个选项都将删除任何develop不在master. 如果这不行,您可以通过创建一个镜像master的最新状态的提交来保留它:

git checkout develop
git merge --no-commit master
git checkout --theirs master .
git commit

回答by Shea Lavington

I'm a bit late to the party, however, after merging my dev branch into the master and pushing to the server, I do the following:

我参加聚会有点晚了,但是,在将我的 dev 分支合并到 master 并推送到服务器后,我执行以下操作:

git fetch

git fetch

git checkout development

git checkout development

git merge origin/master

git merge origin/master

git push

git push

The the dev branch is one commit ahead of the master branch, and other developers don't have to worry about all commits in the development branch being reset.

dev 分支比 master 分支早一次提交,其他开发者不必担心 development 分支中的所有提交都被重置。