Git commit opens blank text file, for what?

前端 未结 17 937
长情又很酷
长情又很酷 2020-12-22 18:33

In all the Git tutorials I\'ve read they say that you can do:

git init
git add .
git commit

When I do that I get a big text file opened up.

相关标签:
17条回答
  • 2020-12-22 19:00

    For those of you using OS X I found this command to work well:
    git config --global core.editor "open -t -W"

    which will force git to open the default text editor (textedit in my case) and then wait for you to exit the application. Keep in mind that you need to "Save" and then "Quit" textedit before the commit will go through. There are a few other commands you can play around with as detailed on this page:

    Apple Developer Library - Open Command

    You can also try git config --global core.editor "open -e -W" if you want git to always open textedit regardless of what the default editor is.

    0 讨论(0)
  • 2020-12-22 19:00

    When doing revision control, you should always explain what the changed you made are. Usually the first time you're have a comment such as "Initial Commit."

    However in the long run you want to make a good comment for each commit. You will want something of the form:

    Added experimental feature x.

    X will increase the performance of feature Y in condition Z. Should you need X activate it with the -x or --feature-eks switches. This addresses feature request #1138.

    0 讨论(0)
  • 2020-12-22 19:03

    Assuming that your editor defaults to vi/vim, you can exit the commit message editor by typing:

    :x
    

    which will save and exit the commit message file. Then you'll go back to the normal git command section.

    More vi commands:
    http://www.lagmonster.org/docs/vi.html

    0 讨论(0)
  • 2020-12-22 19:04

    Try Escape then ZZ, after you're done typing your message. As others have said when you run that commit command it actually runs a text editor to enter the message into. In my case (OS X) it was VI, which I figured out after some digging around. In that case, hit Escape to go into "command" mode (as opposed to INSERT mode) the enter ZZ. I'm sure there are other ways of accomplishing the task but that did it for me. Having never used VI or emacs it wasn't readily apparent to me and wasn't mentioned in any of the beginner guides I was using. Hopefully this helps.

    0 讨论(0)
  • 2020-12-22 19:08

    As mentioned by Ben Collins, without the -m "..." argument to type the commit inline (which is generally a bad idea as it encourages you to be brief), this "big text file" that is opened up is a window in which to type the commit message.

    Usually it's recommended to write a summary in the first line, skip a line, and then write more detailed notes beneath; this helps programs that do things like email the commit messages with an appropriate subject line and the full list of changes made in the body.

    Instead of changing the EDITOR shell variable, you can also change the editor used by adding the additional lines in your ~/.gitconfig file:

    [core]
        editor = emacs
        excludesfile = /Users/will/.gitignore
    

    That second line actually has nothing to do with your problem, but I find it really useful so I can populate my ~/.gitignore file with all those filetypes I know I'll never, ever, want to commit to a repository.

    0 讨论(0)
  • 2020-12-22 19:10

    As all have said this is just where you add your commit comment - but for some it may still be confusing esp if you have not configured your editor settings, and you are not aware of what VI is : then you could be in for a shock, because you will think you are still in the GIT-Bash

    In that case you are in fact in a text editor with some interesting ways of dealing with things and this set of commands may help you out so that you can get past your first commit and then configure an editor you are familiar with or use it as an opportunity to learn how to use it.

    0 讨论(0)
提交回复
热议问题