How to Git Rebase a Branch with the onto Command?
I Have Noticed That the Two Blocks of Following Git Commands Have Different Behaviours and I Don't Understand Why. I Have an a and a B Branches That Diverge...
I have noticed that the two blocks of following git commands have different behaviours and I don't understand why.
I have an A and a B branches that diverge with one commit
---COMMIT--- (A)
\
--- (B)
I want to rebase B branch on the lastest A (and have the commit on the B branch)
---COMMIT--- (A)
\
--- (B)
No problem if I do:
checkout B
rebase A
But if I do:
checkout B
rebase --onto B A
It doesn't work at all, nothing happens. I don't understand why the two behaviours are different.
PhpStorm GIT client uses the second syntax, and so seems to be completely broken, that's why I ask for this syntax issue.
8 Answers
Must Read
tl;dr
The correct syntax to rebase B on top of A using git rebase --onto in your case is:
git checkout B
git rebase --onto A B^
or rebase B on top of A starting from the commit that is the parent of B referenced with B^ or B~1.
If you're interested in the difference between git rebase <branch> and git rebase --onto <branch> read on.