I have a feature branch where I have some commits. Then I did run git rebase master and merged that branch back to master.
So it was like
git checkout -b somebranch
......some work commits here .....
git checkout master
git fetch
git merge origin/master
git checkout somebranch
git rebase master
git checkout master
git merge somebranch
Now I need to pull out all my commits in somebranch out from master completely, possible will need to merge it back to master later.
Update: changes were pushed to master some time ago and there is many commits after merge, so reset to head will not work
So we have something like
and then:
So, at this point, you can easily undo your unwanted merge, by just rewinding master to
B. However, once you pushC(and other people have seen it, and/or done work on top of it), this becomes hard.The simple solution is to just revert all commits on
somebranch:and push.
Now, before you can merge
somebranchagain, you’ll have to rebase it (like you did originally). This works, but you do end up with some noise in the history of master.If a limited number of people have seen and/or committed children, and you can coordinate with them, it’s possible to avoid this, but it’s a lot of work.
You have to make sure everything they’re working on is committed and pushed if possible, and then you can rebase this:
to this:
Now the middle branch will be orphaned, the new head
D'doesn’t have your changes, andsomebranchis still intact so you can merge later.To do this, use:
Everyone else will now have to update to the new head
D', for example by doing:Note that if anyone does have local commits that still depend on
C(and aren’t already visible in thec1..Dchain when you rebase), they’ll need to rebase or cherry-pick them across to the new history. This is potentially a lot of (error-prone) work, so better to avoid if possible.