How can I commit files with git?
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.
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"
in standart Vi editor in this situation you should
- press Esc
- type ":wq" (without quotes)
- Press Enter