A colleague has a problem the other day…
A developer has committed two commits to master that should have been on the start of a development-branch.
- master with commits “B” and “C”.
- And the branch “develop” with commits “D” and “E”.
What was wanted was
- master with only commit “A”
- develop with “B” through “E”
How to do it
The first thing to remember is that branches are nothing more than pointers into the commit-tree. So all we have to do is move some pointers…
First move the commits to the develop-branch. That means rebasing the develop-branch on top of master (since that’s where the two commits are).
git checkout develop
get rebase master
Then reset master
git checkout -B master master^^
git push –force
Note that the commits “D” and “E” are still there, above the master-branch “pointer”. We can’t get rid of them, but they’ll not influence anything.
git checkout master
git merge develop
The full testbed can be downloaded here: