Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a Git commit when VI is on the screen waiting for a commit message?

Tags:

git

People also ask

How do I stop a git commit?

git exit commit message After writing commit message, just press Esc Button and then write :wq or :wq! and then Enter to close the unix file.

How do I exit a committed screen?

Typing :wq and pressing enter should do it, i.e. save the commit message and exit.

How do I stop a commit message?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


You have two options:

  • Provide an empty commit message. If it's a new commit and you haven't yet saved the message, you can simply use :q! (quit without saving). If you’ve already saved (or you're amending a previous commit), just delete the entire log message and save again. This can be done with ggdG + :wq in Vim.

  • Have the editor exit with a non-zero exit code. In Vim, you can use :cq (quit with an error code).

It's worth noting that you can always reset your working copy to the state it was in before the commit with git reset HEAD^.


  • :q! does not work when amending a commit. It does not update the commit message, but it executes the amendment :-(
  • :cq completely aborts the amendment.

To sum up:

  • When creating a new commit (i.e git commit) quit using :q!.
  • When amending (i.e. git commit --amend) remove the commit message (only the first few rows not beginning with a #) for example by holding v and using arrow keys to select it and then pressing Delete. Quit with :wq to apply changes! If you use :q! the changes will be lost and the previous commit message will be used.

When using VIM it's ok in both cases to quit with :cq - VIM will quit with an error code and the commit will be aborted.