Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git commit messages lost by vi

Tags:

git

vim

I'm a clumsy typist, and I don't use vi/vim very often, but I do use it for commit messages. However, if you type a wrong command while editing a commit message (:Wq, say, instead of :wq), when you correctly close out the commit message in vim with :wq or :x, you get this:

error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.

Normally, a wrong command like :W is no problem—vim just ignores it and you can keep on working with the file and save it, but in git commit messages as soon as I mistype, I have irrevocably lost the commit message.

What's going on here, and how do I fix it? (Using git 1.9.1 via homebrew, vim 7.3 as packaged with OS X 10.9)

like image 981
futuraprime Avatar asked Mar 27 '14 21:03

futuraprime


People also ask

How do I fix old commit messages?

To change the most recent commit message, use the git commit --amend command. To change older or multiple commit messages, use git rebase -i HEAD~N . Don't amend pushed commits as it may potentially cause a lot of problems to your colleagues.

How can I see old commit messages?

If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.

Where are git commit messages stored?

The file is located in the . git folder, the file is named "COMMIT_EDITMSG". Show activity on this post. This will allow you to modify your commit, as well as your commit message on your local branch.


1 Answers

You should set vim to not detach from the shell and be in the foreground. You can do this with the following command:

git config --global core.editor vim -f 

From the man:

   -f          Foreground.  For the GUI version, Vim will not fork and detach from the shell it                was  started in.  On the Amiga, Vim is not restarted to open a new window.  This                option should be used when Vim is executed by a program that will wait  for  the                edit  session  to  finish (e.g. mail).  On the Amiga the ":sh" and ":!" commands                will not work. 
like image 195
Aliou Avatar answered Sep 19 '22 14:09

Aliou