How to get back to a point before merging into Github

Asked

Viewed 2,079 times

4

Take a look at my commits chart: https://github.com/danieldspx/cni/network

I took a dump here, I wanted to merge the Workspace branch with the master. The Workspace is the one that was more current, then I wanted to pass pro master and delete the Workspace branch. Just that I went to try to merge and while trying to resolve the conflict of a file I forgot to remove the section:

<<<<<<<< HEAD

{Codigo...}

======

{Codigo...}

>>>>>> origin/workspace

I tried to do a revert for before the merge. I got so much that it’s my last commit. However, I can’t merge this last commit with the latest Workspace commit. He says it’s already up-to-date. I understand I’m committed to the front of Workspace , but it’s because I fucked up. How do I fix this?

2 answers

5


In the local repository:

git reset --hard HEAD^1

The reset command eliminates commits in two ways. Using -hard commit is definitely eliminated.

To delete a commit you need to hash it, but in this case as the previous one you can use HEAD.

The notation 1 is equal to -1, or commit before the HEAD. It is possible to use 2, 3.. n.

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

git push origin master -f

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

Important: both the first and the second command must be used carefully. The first one is possible to "revert" to the local repository through reflog, the second alter is definitely the repository, and other users cloning the repository should synchronize the changes.

  • 1

    How is merge commit, how does the reset HEAD^1 Do you know which parent to go to? I was wondering

  • Vlw caara worked here.

  • Jefferson, I went to the master commit before the merge, now I can not see because I pushed the repository and the chart updated. First of all, run git log --oneline --Graph then you’ll see on ta the merge, then you take the master commit hash before the merge, ai vc do git reset --hard hash_id after that if you rotate git log --oneline --graph will see that the commits of the other branch will not appear because they are in another branch and you in master. If you want to change branch use the git checkout nome_branch

  • 1

    @Jeffersonquesado This may clarify your doubt: https://stackoverflow.com/a/2222920

  • 1

    @hkotsubo answers even. Thanks

1

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

But first, I’ll explain what happened.

I got it, so much so that it’s my last commit. However, I can’t merge that last commit with the last Workspace commit. He says it’s already up-to-date.

This occurred because your merge commit was still there, even though you were doing the revert. See how your repository looked when you revert, CN being the commits in master, W your branch commit workspace, CM the 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 done!

So, ideally delete the merge commit (CM) and revert (RE) with:

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

Making the repository the way it was before:

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

Allowing again the merge among them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.