I had a bad merge, I did not know it was a bad merge until I pushed it to GitHub and now I do not know how to undo/revert it.
The story goes like this:
I opened two distinct branches and committed several changes to those branches. After a while, I decided to merge those branches back to master branch and I use $ git merge branch_name
for this purpose. I merged the first branch and checked out the log of master branch afterwards: all commits on that branch were on master. Then I proceeded with the merging of second branch by the same command. Then I checked the log of master again, where I saw the commits on the branch I merged including a commit with the following comment: "merge branch branch_name". A comment like this was not included when I merged the other branch.
Long story short, the problem is that git merged the commits of the first branch to master like they are the commits of the master already. When you examine the network graph from 'GitHub' or the graph from 'gitg', there is no trace of the first branch left, but its commits are shown as the commits of master branch. There is no problem with the second branch: it is shown separately and it is merged as expected. Also note that, after running the merge commands, I went on deleting the branches by $ git branch -d branch_name
, like it was the most urgent thing to do, unfortunately.
Now I want to go back to the position just before I ran two consecutive merges. Any help is appreciated. If you comment on why this has happened, it will be pleasing as well.
fast-forward
-merge, and this is not a bad thing to happen at all. If you really need to keep the history, in the future, you have to call merge with the--no-ff
option.git reflog
might be of help here, second, whatever you do, if you undo and redo the merge with a non-ff merge, you'll end up having a non-fast-forward push, meaning you have to force-push to github. This is generally a bad thing, because it will cause serious trouble for all people who have pulled the repository in the meantime.