I have 2 branches in Git, namely master and dev .
I'd like to convert dev branch's content into master, that is to say I wanna ditch the state of dev, and change it to how it is like in master, how can I do that?
Thanks!
I have 2 branches in Git, namely master and dev .
I'd like to convert dev branch's content into master, that is to say I wanna ditch the state of dev, and change it to how it is like in master, how can I do that?
Thanks!
Resetting the state of one branch to be exactly the same as another - including the commit history - is known as a reset
in git, not a rebase. This is performed with the reset command.
git checkout dev
git reset --hard master
If dev is a published branch, then you probably want to retain the commit history. The most logical thing to do is to merge master
in to dev
and then reset the tree to match master
's.
E.g.
git checkout dev
git merge master
# ... resolve any conflicts and commit if needed.
# Reset the tree to master
git reset --hard master
# Reset just the branch pointer to the merge
git reset --soft HEAD@{1}
# Commit a 'revert' of the differences to dev
git commit -m "Revert unneeded dev changes"
This will make sure that you won't need to wind back history which is important if people are tracking the dev branch.