如何重新设置开发分支来掌握

我有 developmaster分支,我的 develop分支现在是混乱的,我想重新设置它,使它成为我的 master的副本。我不确定把 master合并到 develop中是否会使两者完全相同。在尝试合并后,我得到了许多冲突,我解决了他们使用:

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

这是否足以使 develop分支成为与 master相同的副本?

谢谢

165681 次浏览

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

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

git branch -f develop master

Or, if you already have develop checked out:

git reset --hard develop master

Note however that both of these options will get rid of any history that develop had 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:

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

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:

git fetch

git checkout development

git merge origin/master

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.

If all else fails, you can delete your current branch and just directly recreate it from master.

git branch -D develop
git checkout master
git checkout -b develop

Reset Last Commit

git reset HEAD~

For example making staging branch identical to develop, one could simply recreate the pointer:

First make sure your local develop branch is up to date with origin/develop by running: git checkout develop && git pull origin develop

Then checkout your target branch (in this case staging) git checkout staging

And finally but not least reset target branch git reset --hard develop

Push changes by brute force (git will complain because local pointer have different address) git push -f

And that would be pretty much it!