2

I have 3 main branches in my git repository, dev, release, and master. I make changes into dev, then merge it to release, and to master when its in production. After I made this merges i push the 3 to github.

I've commited a mistake and somehow merge origin's release into my local dev. You can see in the picture below. I've merged dev into release correctly, but after that there's a merge from origin's release into dev.

enter image description here

I'd like to delete this last commit merge branch 'release' of https://github.... as if it never ocurred.

I've tried to use VSCode revert command:

enter image description here

But I get this message instead:

Error: Unable to Revert Commit
Already up to date!
On branch dev
Your branch is up to date with 'origin/dev'.

nothing to commit, working tree clean
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Marlon
  • 1,719
  • 3
  • 20
  • 42

1 Answers1

4

In Git, the revert command (used by VS Code behind-the-scenes) does not delete the commit(s) in question. Instead, it creates a new commit which undoes the changes. See here for more about revert.

You can use revert with a merge commit if you specify which "side" of the merge to go back to; e.g.

git revert -m 1

However, this is still not what you are looking for. What you want to do is handled by the reset command.

BE CAREFUL: of all the Git commands, reset is one of the easier ways to lose your work! It is relatively difficult, though still possible, to undo the effects of a mistaken reset.

To be safe, you can create a backup of your dev branch first:

git switch dev
git branch dev-backup

The following should remove your merge commit:

git reset --hard HEAD^

If all goes well, you can delete your backup:

git branch -D dev-backup
Daniel Smith
  • 438
  • 4
  • 7