Git commit 打开空白文本文件,有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/60278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 05:45:38  来源:igfitidea点击:

Git commit opens blank text file, for what?

gitgit-commit

提问by vikhyat

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

在我读过的所有 Git 教程中,他们说你可以这样做:

git init
git add .
git commit

When I do that I get a big text file opened up. None of the tutorials seem to address this, so I don't know what to do with the file or what to put in it if anything.

当我这样做时,我打开了一个大文本文件。没有一个教程似乎解决了这个问题,所以我不知道如何处理这个文件,或者如果有的话要放入什么。

回答by vikhyat

You're meant to put the commit message in this text file, then save and quit.

您打算将提交消息放在此文本文件中,然后保存并退出。

You can change the default text editor that git uses with this command:

您可以使用以下命令更改 git 使用的默认文本编辑器:

git config --global core.editor "nano"

You have to change nano to whatever command would normally open your text editor.

您必须将 nano 更改为通常会打开文本编辑器的任何命令。

回答by Will Robertson

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.

正如Ben Collins所提到的,如果没有-m "..."输入内联提交的参数(这通常是一个坏主意,因为它鼓励您简短),打开的这个“大文本文件”是一个输入提交消息的窗口.

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 EDITORshell variable, you can also change the editor used by adding the additional lines in your ~/.gitconfigfile:

除了更改EDITORshell 变量之外,您还可以通过在~/.gitconfig文件中添加额外的行来更改使用的编辑器:

[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 ~/.gitignorefile with all those filetypes I knowI'll never, ever, want to commit to a repository.

第二行实际上与您的问题无关,但我发现它非常有用,因此我可以~/.gitignore用我知道我永远不想提交到存储库的所有文件类型填充我的文件。

回答by Lou

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.

正在打开的文本文件是当前提交操作的摘要。git commit 会将您放入此文件,以便您可以在文件顶部添加提交消息。添加消息后,只需保存并退出此文件即可。

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

此命令上还有一个“-m msg”开关,允许您在命令行上添加提交消息。

回答by MatthiasS

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

假设您的编辑器默认为 vi/vim,您可以通过键入以下内容退出提交消息编辑器:

:x

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

这将保存并退出提交消息文件。然后你会回到正常的 git 命令部分。

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

更多 vi 命令:http:
//www.lagmonster.org/docs/vi.html

回答by MatthiasS

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

如果您使用的是 Mac OS X 并使用 BBEdit,您可以将其设置为提交消息的首选编辑器:

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

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

完成编辑后,保存并关闭文件,git 将使用它进行注释。

回答by Stephen Bailey

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 VIis : then you could be in for a shock, because you will think you are still in the GIT-Bash

正如所有人所说,这只是您添加提交评论的地方 - 但对于某些人来说,特别是如果您尚未配置编辑器设置,并且您不知道VI是什么,它可能仍然令人困惑:那么您可能会感到震惊,因为你会认为你还在 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 commandsmay 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.

在这种情况下,您实际上是在一个文本编辑器中,使用一些有趣的处理方式,这组命令可以帮助您解决第一次提交,然后配置您熟悉的编辑器或将其用作一个学习如何使用它的机会。

回答by Greg Hewgill

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

-m提交选项允许你输入一个提交命令行消息:

git commit -m "my first commit"

回答by nothankyou

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

当你创建一个新的提交时,git 会启动一个文本编辑器并向其中写入一些内容。

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.

完成后,保存并退出文本编辑器。Git 将使用您编写的内容作为提交消息。

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.

提交消息的第一行用作消息头(或标题)。提交标头的首选长度小于 40 个字符,因为这是 github 在截断给定存储库的“提交”选项卡上显示的字符数,有些人觉得这很烦人。

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).

身体可以由你喜欢的任何东西组成。对您的提交引入的更改的概述是合理的。一些第三方应用程序使用包含提交消息正文的信息来触发各种钩子(我在想 Gerrit 和 Pivotal Tracker,仅举两个例子)。

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
#

Hereone Mr. Torvalds opines on what makes a good commit.

在这里,Torvalds 先生对什么是好的承诺提出了意见。

And hereTpope does likewise.

这里Tpope做同样。

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"

回答by TheGeoff

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.

输入完消息后,尝试 Escape 和 ZZ。正如其他人所说,当您运行该提交命令时,它实际上会运行一个文本编辑器来输入消息。在我的情况下(OS X)它是 VI,我经过一番挖掘后发现。在这种情况下,按 Escape 进入“命令”模式(与插入模式相反),然后输入 ZZ。我确信还有其他方法可以完成任务,但这对我来说是可行的。从未使用过 VI 或 emacs 对我来说并不明显,并且在我使用的任何初学者指南中都没有提到。希望这会有所帮助。

回答by Ben Collins

The git commitcommand will open up the editor specified in the EDITORenvironment 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.

git commit命令将打开EDITOR环境变量中指定的编辑器,以便您可以输入提交注释。在 Linux 或 BSD 系统上,默认情况下应该是 vi,尽管任何编辑器都可以工作。

Just enter your comments and save the file.

只需输入您的评论并保存文件。