GitForJava
GitForJava

Reputation: 299

Adding a git commit message using vi on OS X

I'm learning using Git on an OS X Terminal. It seems really easy. But I can't handle just one problem: When I try to merge two branches, for example "myTestBranch" into "master" this program covers the terminal and shows me a new view where I should write the merge message. And then, I don't know how to do "Enter", save the merge message and then come back to the main terminal view where I can continue working.

Does anyone know, how does it work?

What I see, when i try to merge

Upvotes: 29

Views: 32808

Answers (2)

Raúl Omaña
Raúl Omaña

Reputation: 921

If you haven't change the default git's editor, that "new view" is the Vi program.

To save your commit message using Vi, follow the next steps:

  1. Type i
  2. Write your message
  3. Type the ESC key
  4. Type :wq
  5. DONE! :D

Typing :q, step 4, is not enough beacuse just means QUIT without saving. That's why you need :wq, which means WRITE and QUIT.

You can write your commit message using your favourite editor(vim, emacs, etc.). To achieve this, you can use configuration parameter or environment variables, listed in order:

  1. GIT_EDITOR environment variable
  2. core.editor configuration option
  3. VISUAL environment variable
  4. EDITOR environment variable

Using the configuration option type something like this:

$git config --global core.editor "nano"

Or if you want to use enviroment variables, add something like this to your .bash_profile

$export GIT_EDITOR="PATH/TO/YOUR/EDITOR"

Upvotes: 54

Jelle
Jelle

Reputation: 586

By default Git will open Vim as editor.

You basically need to type 'I' to start editing. After that ESC and type :q to quit or :w to save the file. You can also combine them: :wq to save and exit Vim.

For more information about Vim check the official documentation

To change Vim for any other editor check the Git Environment Variables or older posts with a similar question: How do I make Git use the editor of my choice for commits?

Upvotes: 16

Related Questions