15

I'm doing a git revert on a commit using git revert [commit number]

Real life example being:

git revert 58c128313e353b8dd7d04121824b966faefe68dc

After I do this it takes me to the screen where it shows me the revert message, but I can't exit this screen and I can't type anything.

I've tried pressing Q which is how I quit the git log screen, but this doesn't work either. When I force quit terminal and go back in, the revert has taken place.

How do I do a revert and then got back to the command line and carry on working as usual?

Screenshot

Here is the screenshot of what it is saying

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
pjk_ok
  • 618
  • 7
  • 35
  • 90
  • 1
    I guess vim opened for you: Try `ESC` then `:q` followed by `Enter` – Sbls Feb 09 '17 at 20:05
  • It is likely asking for a commit message and brought up the screen in VIM. Try entering `esc` (to clear anything you mightve entered) then `:q`and `enter` EDIT: @Sbls beat me to it. – sudo_coffee Feb 09 '17 at 20:05
  • Neither of those worked. I'll upload a screen shot of what it is saying. – pjk_ok Feb 09 '17 at 20:09
  • actually I can't see how to upload a screenshot? – pjk_ok Feb 09 '17 at 20:10
  • Possible duplicate of [How to exit the Vim editor?](http://stackoverflow.com/questions/11828270/how-to-exit-the-vim-editor) – 1615903 Feb 10 '17 at 07:30
  • I don't think this should be a duplicate because I spent a long time searching this site for a solution before posting the question and being new / relatively new to GIT i had no idea I was in the Vi editor or what it even was. The fact that this answer is here might well help / save a lot of time for someone in the future. – pjk_ok Feb 10 '17 at 15:01

1 Answers1

19

You are in the vi or vim editor, which is the default on many Linux distributions.

To save the file and exit, thus completing your revert, type:

Esc:wqEnter

Or you can abort the editor without saving, if you prefer that:

Esc:q!Enter

You can avoid this editor in the future if you wish. Find an editor you do want to use (emacs, nano, joe, whatever...) and set it as your default instead. You can do that in your shell file (e.g. .bash_profile) like this:

export EDITOR=/usr/bin/nano
export VISUAL=$EDITOR
Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
  • 2
    You're missing `:`? – sudo_coffee Feb 09 '17 at 20:18
  • 1
    @sudo_coffee Wow that's embarrassing ;) Thanks for the note, I fixed it. – Dan Lowe Feb 09 '17 at 20:19
  • It was the esc : q ! enter version that worked. Thanks. When I check git status afterwards, it's not showing back in my staging area? Surely if i'm reverting it from a commit this is where it should go? – pjk_ok Feb 09 '17 at 20:28
  • @EmilyChewy No, `git revert` creates a new commit which has the effect of reversing everything from the commit you chose to revert. It's like a patch, but to undo an earlier commit. Since a new commit is created, your staging area will be empty. – Dan Lowe Feb 09 '17 at 22:16
  • Ah, I see. Thanks Dan. – pjk_ok Feb 09 '17 at 22:23