How do I use git rebase to move a commit?

0

Issue

This is the state of my local repo. I was at AAAAA and made commit CCCCC. I did a git pull and it pulled the commits and did an auto(ish) merge of BBBBB into CCCCC and made DDDDD. I don’t want that, so I killed DDDDD with a git reset.

$ git tree –all

CCCCC (HEAD, main) foobar issue 666
| * BBBBB (tag: fubar, origin/main, origin/HEAD) fubar issue #69
|/  
* AAAAA foo

Instead of a merge, I want to move CCCCC onto BBBBB. How do I rebase this? Do I need to do a switch or checkout to BBBBB first?

* CCCCC (HEAD, main) foobar issue 666
* BBBBB (tag: fubar, origin/main, origin/HEAD) fubar issue #69
* AAAAA foo

Solution

Rebase is correct:

git fetch
git switch main
git rebase origin/main

You could probably just say git pull --rebase instead, but I’m not one to take chances.

Answered By – matt

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More