开发者

How do I properly rebase a git's branch into another?

开发者 https://www.devze.com 2022-12-17 03:23 出处:网络
I have 2 branches in Git, namely master and dev . I\'d like to convert dev 开发者_如何学Cbranch\'s content into master, that is to say I wanna ditch the state of dev, and change it to how it is like

I have 2 branches in Git, namely master and dev .

I'd like to convert dev 开发者_如何学Cbranch'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.

0

精彩评论

暂无评论...
验证码 换一张
取 消