merger merger - 1 year ago 78
Git Question

Undo a merge after time, what happens?

How do i undo a merge that has been pushed and later been branched off? And what happens to the repo?

This has been asked in different variations before but im not sure if any of the answers explains what happens after.

Assume this is the state of the repo:

\ / \
D--E--F I--J

After reading several answers i assume the i should do a git revert?? on G? Or git reset?

What happens to the H,I,J code, that may use some of the code that was merged, if i do a git reset or git revert on the FG merge?

Im still a noob on using the more advanced features of git :/

Edit1: I should mention that this isn't a public repo. All the branches are maintained by a small inhouse team.

Answer Source

What i want is to undo the merge and continue working on the DEF branch

Undoing a merge through a revert is one way which at least does not change the history of the main branch

git revert -m 1 G

And you can go on on branch DEFn which is unaware of the merge: you can add new commits and merge later. However, as commented by lucash, that will not reapply the changes from commits D, E and F but only merge the new commits from that branch, most probably leading to problems due to the missing changes which were aware in the DEF branch.
So you will need first to revert the revert-commit (result of git revert -m 1 G) before merging the branch to avoid that problem.

IJK can remain on H: the revert would have cancelled changes introduced by G, and would not have affected H.

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