118

None of the tutorials will help!
They all do that thing where they just assume I know what to do..

Currently, my terminal window starts with..

# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: httpdocs/newsite/manifest/cache/0a432970ba6491fe65dad60b012e5c95_louloumay2011en-1-4dea3186b7f7b.jpg # deleted: httpdocs/newsite/manifest/cache/0a61b5d7a9e97da78fe602e1ad41edb6_5-4dec7c3d57c80.jpg # deleted: httpdocs/newsite/manifest/cache/0afb6a7716a85d0de46cdd03bb30f75f_fifa_panorama_full_page-01_thu-4dea3d1a0e0f5.jpg # deleted: httpdocs/newsite/manifest/cache/0b3bc9be76a5d3e1e36af4b8dcf98658_free2-4df0e2e08761f.jpg # deleted: httpdocs/newsite/manifest/cache/0b6342913b8e599fac76da452af98ec5_si-feb-2009-1-4dea3d1abcb61.jpg # deleted: httpdocs/newsite/manifest/cache/0b9ddc587340f7744e03c4b2dafacf7f_lou-lou-winter-2009-cover-4dea3d1a9b1a0.jpg # deleted: httpdocs/newsite/manifest/cache/0bf64ff8fc22720b3da20d0730fa6a04_chatelaine-dec-2009-4dea3d18daa30.jpg # deleted: httpdocs/newsite/manifest/cache/0bf664e03eb0a2255b69b02aed85add0_summumfeb2011-2-4dea3188766aa.jpg 

but there's no way to know how to do what they say to do here..
http://learn.github.com/p/normal.html

All it says is

We simply type our commit message and exit the editor.

What does that mean?!
Just because you write the word simply doesn't mean it is simple..

When I start to type it does wierd stuff, says "recording" or "inserting" and there are about 300 files, and it wants me to replace every line with a message?!?

Help !

I would use their handy Mac application for this, but if it's over 20 files or so, it freezes up !
What's up with that??

5
  • 16
    That has nothing to do with my question. If I said "how do ski down a hill" then you tell a person how to ski, you don't say "well, why are you on a mountain" Commented Aug 16, 2011 at 15:36
  • 3
    A commit without a -m argument launches a text editor where you can make your comments. (Probably defaulting to vim in this case.) The tutorial author is assuming that you already know how to use it. Commented Aug 16, 2011 at 15:39
  • Someone more familiar with OSX than I can probably tell you how to set your default editor to something different. Usually it's "export EDITOR=/path/to/whatever" in your shell startup configuration. Commented Aug 16, 2011 at 15:45
  • @Alex: git config --global core.editor '/path/to/editor' Commented Aug 16, 2011 at 16:19
  • 6
    -1 for the RT[F]M. The default editor would appear to be the problem, not lack of reading the git documentation. Commented Aug 16, 2011 at 16:26

11 Answers 11

116

When you run git commit with no arguments, it will open your default editor to allow you to type a commit message. Saving the file and quitting the editor will make the commit.

It looks like your default editor is Vi or Vim. The reason "weird stuff" happens when you type is that Vi doesn't start in insert mode - you have to hit i on your keyboard first! If you don't want that, you can change it to something simpler, for example:

git config --global core.editor nano 

Then you'll load the Nano editor (assuming it's installed!) when you commit, which is much more intuitive for users who've not used a modal editor such as Vi.

That text you see on your screen is just to remind you what you're about to commit. The lines are preceded by # which means they're comments, i.e. Git ignores those lines when you save your commit message. You don't need to type a message per file - just enter some text at the top of the editor's buffer.

To bypass the editor, you can provide a commit message as an argument, e.g.

git commit -m "Added foo to the bar" 
Sign up to request clarification or add additional context in comments.

6 Comments

When you say "ignore" does that mean it will stay staged?
No, those lines don't affect what is going to be committed. Those files will still be committed even if you delete the comment lines. They're just a reminder of what the status of your repository was when you ran the git commit command.
So if I run the commit, the change will be recorded, even if there is a # on that line?
That is correct. What's committed is what has been git add-ed to the index.
Another option is instead of git commit, you can run git commit -a -m "Your message for the commit" Then no editor will run.
|
63

in standart Vi editor in this situation you should

  1. press Esc
  2. type ":wq" (without quotes)
  3. Press Enter

1 Comment

This was my case. But pressing Esc didn't work, just the colon. Then, I typed q! to not save any changes. When the terminal is full of text without a prompt (dollar sign) usually is Vi!
31

It sounds as if the only problem here is that the default editor that is launched is vi or vim, with which you're not familiar. (As quick tip, to exit that editor without saving changes, hit Esc a few times and then type :, q, ! and Enter.)

There are several ways to set up your default editor, and you haven't indicated which operating system you're using, so it's difficult to recommend one in particular. I'd suggest using:

 git config --global core.editor "name-of-your-editor" 

... which sets a global git preference for a particular editor. Alternatively you can set the $EDITOR environment variable.

2 Comments

Your vim cheat sheet is valuable, especially for those who come from that "an icon is worth a thousand command lines ;-)" community
I just found viemu.com/a-why-vi-vim.html to be particularly helpful in explaining why vi/vim is still here. Then migrate to the keyboard cheat sheet viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
22

The command for commiting all changed files:

git commit -a -m 'My commit comments' 

-a = all edited files

-m = following string is a comment.

This will commit to your local drives / folders repo. If you want to push your changes to a git server / remotely hosted server, after the above command type:

git push 

GitHub's cheat sheet is quite handy.

1 Comment

epic bro nice thx
17

I don't know your system environment, but it seems, that you have typed:

git commit 

And your default editor has been launched. In the worst case scenario (for you) it could have been vim :)

If you don't know how to quit vim, use :q.

If you have further problems, you could use

git commit -m 'Type your commit message here' 

3 Comments

Is there a way to choose a different editor that it will open with? Like nano?
Sure: this should change default editor to nano: git config --global core.editor nano
message in double quotes.. "Message"
4

It looks like all of the edits are already a part of the index. So to commit just use the commit command

git commit -m "My Commit Message" 

Looking at your messages though my instinct says that you probably don't want the cache files to be included in your depot. Especially if it something that is built on the fly when running your program. If so then you should add the following line to your .gitignore file

httpdocs/newsite/manifest/cache/* 

2 Comments

it was a sub project, the whole dir is being removed.
To see what all commands git has type git --help this will give you all the commands like commit, push, pull, clone etc. To get help on a specific command and what the switches are available type git commit --help, git push --help this should work on linux and mac command line. If you want a good command line app, I would recommend the same one github does git-scm link on this page. help.github.com/mac-set-up-git
3

Git uses "the index" to prepare commits. You can add and remove changes from the index before you commit (in your paste you already have deleted ~10 files with git rm). When the index looks like you want it, run git commit.

Usually this will fire up vim. To insert text hit i, <esc> goes back to normal mode, hit ZZ to save and quit (ZQ to quit without saving). voilà, there's your commit

Comments

3

This happens when you do not include a message when you try to commit using:

git commit 

It launches an editor environment. Quit it by typing :q! and hitting enter.

It's going to take you back to the terminal without committing, so make sure to try again, this time pass in a message:

git commit -m 'Initial commit' 

1 Comment

This actually helped me more than the accepted answer by explaining the context, what is happening and how to make "weird stuff" normal again.
2

I faced the same problem , i resolved it by typing :q! then hit Enter And it resolved my problem After that run the the following command git commit -a -m "your comment here"

This should resolve your problem.

2 Comments

That answer is given here already (stackoverflow.com/a/7080907/2827823) ... twice actually, so we don't need one more.
I come across this when I try to merge branches, If you want it to continue without adding in a commit message just type :q (without the !)and enter, It will continue to commit with an auto generated commit message stating that the two branches had been merged, Much better commit message and more clear compared to writing your own.
1

git commit alone without -m will take you to the terminal Vi editor. You need to get back out of Vi now to the main terminal UI. Here's how:

  1. Press Esc
    Important: You won't see anything after pressing Esc and it looks like nothing happened. Trust something has.

  2. Next, type :wq
    Note that :wq appears at the bottom left of the editor below the tildes. That's how you know pressing Esc before typing it got you to this next step.

  3. Press Enter

To get around these extra steps in the future, shortcut by committing this way:

git commit -m "some commit message about what you did"

The -m ‹commit message› is what makes the difference.

1 Comment

Love these edits! Thank you for making my first Stack Overflow post cleaner and concise.
-2

You can make a commit using Visual Studio UI. It is another way to do it

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.