Reputation: 10154
I have the following situation in a Git repository
A - B [origin/master] \ C [origin/X] \ E - F [origin/Y]
I didn't realise when I started Y
, that I had branched from X
, I had intended to branch from master
.
How can I rebase Y
onto master without including commit C
?
(Changes on X
are to a file not touched by the commits on Y
)
I'd like to end up with the following:
A - B [origin/master] \ \ \ E - F [origin/Y] \ C [origin/X]
I tried git rebase master
and it doesn't seem to have changed anything, output was :
Current branch Y is up to date.
Upvotes: 0
Views: 67
Reputation: 1970
As is always the case in Git there are probably lots of ways of achieving this, however the following should work:
Y
reset this to master
: git reset --hard master
.git cherry-pick C..F
(assuming E
and F
are the first and latest commit IDs on your branch after C
).Edited: As @eftshift0 pointed out I initially had the wrong commit ID's in my git cherry-pick
statement - fixed now.
Upvotes: 0
Reputation: 30307
It can be easily done like this:
git rebase --onto origin/master origin/X origin/Y
Given that you are using remote references, you will be on detached HEAD so you have to do this to push your resulting branch into origin's branch Y:
git push origin -f HEAD:Y
Upvotes: 2