Qwerty Qwerty - 1 year ago 115
Git Question

Git merge in wrong direction

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

. It's just the final destination (and arrow in history) which is wrong.

now: enter image description here desired: enter image description here

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.

Answer Source

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 it.


git checkout devel
git reset --hard master
git checkout master
git reset --hard <previous-commit-id>

That should do the trick.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download