I have finished a lengthy merge of a devel branch onto master, then I realised it should have been a devel update instead, meaning the direction should be master -> devel. Is it possible to change the destination of the commit, so that the arrow is pointing from master to devel?
note: The resulting changes in files would be exactly same for both d->m
and m->d
. It's just the final destination (and arrow in history) which is wrong.
now: desired:
blue: master
red: devel
*Changes are not commited or pushed yet.
- I resolved all conflicts in a devel->master merge.
- I haven't commited or pushed the changes.
- Changes are made on top of master.
- I need to apply the resolved conflicts in a master->devel direction.
You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.
In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.
A reintegration merge, also known as a back merge is appropriate when the changes made in a branch need to be integrated back into the branch's ancestor.
Reverting a merge on the branch is as simple as determining which commit was the previous one.
First, checkout on the branch you want to modify. It's a git-golden-rule: you can only modify the branch you're on.
git checkout master
Then, figure out the previous-master commit it, and force master back into its previous state
git reset --hard <previous-commit-id>
Finally, do your merge right
git checkout devel
git merge master
What you could also do, if you want to be lazy, is invert branch states.
You still need to find master's previous commit-id.
Then:
git checkout devel
git reset --hard master
git checkout master
git reset --hard <previous-commit-id>
It's actually a bit simpler than anwser of @blue112 . First commit the master locally.
git checkout master
git commit
This will create a shared commit for master and devel. Then switch to devel and merge it also with master. This will result in a fast-forward merge as there aren't any conflicts left.
git checkout devel
git merge master
It should be save to push devel now.
git push devel origin/devel
Now revert master back to its previous commit, so it remains as it was before the merge:
git checkout master
git reset --hard <previous-commit-id>
Workspace should be clean and safe now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With