How do I get back to a point before a merge in GitHub?

4

Take a look at the graph of my commits: link

I did a crap here, I wanted to do a merge of the branch workspace with the master. The workspace is what was most current, so I wanted to pass the master and delete the workspace branch. So I was trying to merge and trying to resolve the conflict in a file I forgot to take the section:

<<<<<<<< HEAD

{Codigo...}

======

{Codigo...}

>>>>>> origin/workspace

I tried to make a revert to before the merge. I got it, so much is my last commit. However I can not merge this last commit with the last commit of the workspace. He says it's already up-to-date. I understand how to commit with the front of workspace, but it's because I did shit. How do I fix this?

    
asked by anonymous 07.06.2018 / 00:07

2 answers

5

In the local repository:

git reset --hard HEAD^1

The reset command eliminates commits, in two ways. Using --hard the commit is permanently deleted.

To delete a commit it is necessary to pass the hash, but in this case it is possible to use HEAD.

The ^ 1 notation equals -1, that is, commit prior to HEAD. You can use ^ 2, ^ 3 ... ^ n.

Now that oncommit has been deleted, just send it to GitHub, using:

git push origin master -f

O -f is force, it will equalize the remote repository with what is being sent.

Important: Both the first and second commands should be used with care. The first one is possible to "revert" to the local repository through reflog, since the second finally changes the repository, and other users cloning the repository should synchronize the changes.

    
07.06.2018 / 15:16
1

Resolving your problem, allowing the branch merge to work again, is resolved by deleting the merge commit from branch master and, in your case, also deleting the commit from revert.

But first, I'll explain what happened.

  

I have achieved so much that it is my last commit. However I can not merge this last commit with the last commit of the workspace. It says it's already up-to-date.

This was because your merge commit was still there, even doing revert . See how your repository was when you did the revert, CN being the commits in the master, W the commit of your branch workspace , CM merge commit and RE your revert:

                   .--D--.                          << workspace
                  /       \
C1<---C2<---C3<--´---------CM<---RE                 << master

If you try to merge again between workspace and master, see that Git understands that the merge has already been made!

So, the ideal is to delete the commit of merge ( CM ) and revert ( RE ) with:

git checkout master
git reset --hard HEAD~2 # apaga os dois últimos commits da master

Making the repository look like it used to be:

                   .--D              << workspace
                  /       
C1<---C2<---C3<--´                   << master

Re-enabling merge between them.

    
20.08.2018 / 18:04