简体   繁体   中英

how to reset develop branch to master

I have develop & master branches, my develop branch 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 master into develop will make both of them identical. after trying to merge i got many conflicts i solved them using:

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

is this enough for develop branch to be an identical copy to master ?

Thanks

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

重置上次提交

git reset HEAD~ 

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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM