This question already has an answer here:
- Undo a Git merge that hasn't been pushed yet 29 answers
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
Just find the last commit of the develop branch before merge, and then reset your git history to that commit.
You can use graphical tool like
gitk
orgit 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.
git revert
is useful when the changes you want to undo were already published. It basically reverts the changes operated by another commit (removes the added lines, adds the removed lines, changes in the other direction the changed lines).It is similar with an "Undo" operation but it usually happens after other commits were already added to the branch and it creates new commit(s).
Since you didn't publish your changes, the best solution is to use
git reset --hard
.If you are on the
develop
branch and you last command wasgit merge feature/forum_kolo_3
, by runninggit reset --hard HEAD^1
. It moves the current branch (develop
) to the first parent of the merge commit (i.e. where it was before the merge).