Search code examples
gitgithubmergeresetrevert

GitHub revert or reset?


As you can see in the picture, I was working in feature forum_kolo_3, I decided to finish that feature and merge it to develop (but did not pushed the changes to remote develop, so its just local changes) and than I realized it was a bad idea and now I want to remove this merge, like it never happened.

So similar situation as described in here:git revert not allowed due to a merge but no -m option was given

But Im not quite sure what to do now, reverse or reset? I want to undo the merge I just did.

I also found this How to revert Git repository to a previous commit?

git revert --no-commit 0766c053..HEAD

git commit

Which seems like a better idea...but I have no clue

sourctree


Solution

  • Just find the last commit of the develop branch before merge, and then reset your git history to that commit.

    git reset --hard <pre_merge_last_commit_id>
    

    You can use graphical tool like gitk or git log --oneline --decorate=full --graph to find the last commit of the develop branch.

    Note: Make sure you don't reset to the last commit of the feature branch instead.