Reputation: 3636
I have branched off the wrong branch and I want to move a commit to the master instead of a feature branch. Tried with rebase master from feat2 but I'm getting "Current branch ... is up to date"
Basically I want to go from this
feat2 F
/
feat1 C - D - E
/
master A - B
To this
feat1 C - D - E
/
master A - B
\
feat2 F
Of course F does not depend on any of C-D-E
EDIT: Forcing the rebase reveals that not only F is considered for it on feat2 but all of the commits from master are rebased (C-D-E-F). What I need is a way to tell rebase to "cut" at feat1.
Upvotes: 3
Views: 84
Reputation: 521194
Try using git rebase --onto
:
git checkout feat2
git rebase --onto E B
This says to rebase the commit F
whose parent is E
on top of commit B
. This leaves feat2
looking as you want, with the F
commit sitting directly on top of B
.
Another simple way of handling this would be to branch a new feature 2 branch feat2new
from master
, then cherry-pick commit F
. After this, you can delete the old feat2
branch and rename feat2new
to feat2
:
git checkout master
git checkout -b feat2new
git cherry-pick <SHA-1 for commit F>
Now delete feat2
, and do the rename:
git branch -d feat2
git branch -m feat2new feat2
Upvotes: 1