Git commit opens blank text file, for what?

前端 未结 17 936
长情又很酷
长情又很酷 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 18:52

    Yeah, make sure you have a sensible editor set. Not sure what you're default editor will be but if, like me, it is nano (will say somewhere near the top after you type commit) you just need to type in a comment and then hit Ctrl-x to finish. Then hit y, followed by enter to affirm the commit.

    Also, if you want to see a simple list of the files you'll be committing rather than a huge diff listing beforehand try

    git diff --name-only
    0 讨论(0)
  • 2020-12-22 18:56

    If you’re on Mac OS X and using BBEdit, you can set this up as the editor of choice for commit messages:

    git config --global core.editor "bbedit -w"
    

    Once finished edit, save and close the file and git will use it for the comments.

    0 讨论(0)
  • 2020-12-22 18:56

    The git commit command will open up the editor specified in the EDITOR environment variable so you can enter a commit comment. On a Linux or BSD system, this should be vi by default, although any editor should work.

    Just enter your comments and save the file.

    0 讨论(0)
  • 2020-12-22 18:58

    The text file that is being opened is a summary of the current commit operation. The git commit drops you into this file so the you can add a commit message at the top of the file. Once you've added your message just save and exit from this file.

    There is also a "-m msg" switch on this command that allows you to add the commit message on the command line.

    0 讨论(0)
  • 2020-12-22 18:59

    The -m option to commit lets you enter a commit message on the command line:

    git commit -m "my first commit"
    
    0 讨论(0)
  • 2020-12-22 19:00

    When you create a new commit, git fires up a text editor and writes some stuff into it.

    Using this text editor, the intention is for you to write the commit message that will be associated with your feshly created commit.

    After you have finished doing so, save and exit the text editor. Git will use what you've written as the commit message.

    The commit message has a particular structure, described as follows:

    The first line of the commit message is used as the message header (or title). The preffered length of the commit header is less than 40 characters, as this is the number of characters that github displays on the Commits tab of a given repository before truncating it, which some people find irritating.

    When composing the header, using a capitalized, present tense verb for the first word is common practice, though not at all required.

    One newline delineates the header and body of the message.

    The body can consist whatever you like. An overview of the changes introduced by your commit is reasonable. Some third party applications use info included the body of commit messages to set off various kinds of hooks (I'm thinking Gerrit and Pivotal Tracker, to name two).

    Here's a short and sweet example. A leading # denotes a comment.

    Gitignore index.pyc
    
    Ignore gunicorn generated binary file
    # Please enter the commit message for your changes. Lines starting
    # with '#' will be ignored, and an empty message aborts the commit.
    # On branch dev
    # Your branch is ahead of 'origin/dev' by 10 commits.
    #   (use "git push" to publish your local commits)
    #
    # Changes to be committed:
    #   (use "git reset HEAD <file>..." to unstage)
    #
    #   modified:   .gitignore
    #
    

    Here one Mr. Torvalds opines on what makes a good commit.

    And here Tpope does likewise.

    As stated in several other answers, changing the default editor is a one-liner on the command line.

    For my preference:

    git config --global core.editor "vim"
    
    0 讨论(0)
提交回复
热议问题