2

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

Community
  • 1
  • 1
Honza
  • 323
  • 3
  • 14

2 Answers2

2

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).

now I want to remove this merge, like it never happened.

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 was git merge feature/forum_kolo_3, by running git 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).

axiac
  • 68,258
  • 9
  • 99
  • 134
1

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.

hspandher
  • 15,934
  • 2
  • 32
  • 45