0

Possibly a dumb question:

I want to revert last commit. I have it's hash. I do:

git revert <bad hash>

And I get:

Revert "message of the last commit I am reverting"

This reverts commit 421357bf17ae...etc.

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is up to date with 'origin/master'.
#
# Changes to be committed:
#       modified:   ...certain file
#       deleted:    ...certain file
#       etc..
#
~
~
~
~
~
C:/Users/rest-of-path/.git/COMMIT_EDITMSG [unix] (07:55 08/01/2021)                         1,1 All
"C:/Users/rest-of-path/.git/COMMIT_EDITMSG" [unix] 20L, 747C

And I don't know what to do from here. If I write on the keyboard, the message at the start will be edited, but when I press enter, nothing happens.

I know that I am creating a new commit here, I just don't know what to press to confirm the creation of this new commit. Assume I am happy with the default message "Revert bla bla" - how to confirm the new commit?.

Thank you for any help.

Ghadir
  • 507
  • 10
  • 21

1 Answers1

0

You can use reset or revert command to undo your last commit. They both work differently.

In Your case you are using Git revert command

In your case you are trying to undo you last commit with git revert command.

so technically, you are adding one more commit (to undo a commit).

It seems you can simply undo last commit with git reset, see below.

Git reset command

To reset last commit, you can try

git reset --hard HEAD~1

Also its important to mention, as you are using HARD option your last commit changes will be lost.

And if you want to keep your last commit changes (and just trying to undo your commit you can use soft option or simply the following git command)

git reset HEAD~  

Hope it will help.

Rajeev Bera
  • 2,021
  • 1
  • 16
  • 30
  • Thank you, I guess I could have done it that way too, but this is not exactly what I was asking for. It turned out it's a problem with how to exit the VIM editor (which was solved by pressing ESC to return to normal mode, and then typing `:q` – Ghadir Jan 08 '21 at 06:49