Convenient way to do "wrong way rebase" in git?

Posted by Kaz on Stack Overflow See other posts from Stack Overflow or by Kaz
Published on 2013-10-24T03:02:40Z Indexed on 2013/10/24 3:54 UTC
Read the original article Hit count: 178

Filed under:
|

I want to pull in newer commits from master into topic, but not in such a way that topic changes are replayed over top of master, but rather vice versa. I want the new changes from master to be played on top of topic, and the result to be installed as the new topic head.

I can get exactly the right object if I rebase master to topic, the only problem being that the object is installed as the new head of master rather than topic.

Is there some nice way to do this without manually shuffling around temporary head pointers?

Edit:

Here is how it can be achieved using a temporary branch head, but it's clumsy:

git checkout master
git checkout -b temp   # temp points to master
git rebase topic       # topic is brought into temp, temp changes played on top

Now we have the object we want, and it's pointed at by temp.

git checkout topic
git reset --hard temp

Now topic has it; and all that is left is to tidy up by deleting temp:

git branch -d temp

Another way is to to do away with temp and just rebase master, and then reset topic to master. Finally, reset master back to what it was by pulling its old head from the reflog, or a cut-and-paste buffer.

© Stack Overflow or respective owner

Related posts about git

Related posts about git-rebase