git commit - 混乱

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4164874/
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 09:28:07  来源:igfitidea点击:

git commit -a confusion

gitvim

提问by Slee

I am using Git Bash and am trying to figure out what is happening when I type 'git commit -a'.

我正在使用 Git Bash 并试图弄清楚当我输入“git commit -a”时发生了什么。

Looks like VIM opens up to edit my commit message but how do I save and actually complete this commit? I type in the editor and hit enter but it just creates another line.

看起来 VIM 可以打开以编辑我的提交消息,但是如何保存并实际完成此提交?我在编辑器中输入并按回车键,但它只会创建另一行。

FYI: I am using VM Fusion on my mac so some of my keys might be a little different

仅供参考:我在我的 mac 上使用 VM Fusion,所以我的一些键可能有点不同

采纳答案by Crozin

Just leave VIM (command mode-> :wq).

只需离开 VIM(命令模式-> :wq)。

-aflag works like:

-a标志的工作原理如下:

git add -u
git commit ...

-mflag specifies commit message. That message is mandatory so if you don't pass that (git commit -m "My message") the default text editor will be opened (you can change it in git configuration) and you'll have to write a commit message, then save and quit the editor.

-m标志指定提交消息。该消息是强制性的,因此如果您不通过 ( git commit -m "My message") 将打开默认文本编辑器(您可以在 git 配置中更改它)并且您必须编写提交消息,然后保存并退出编辑器。

回答by knittl

this is a question about VIM and not git itself (if i'm not mistaken)

这是一个关于 VIM 而不是 git 本身的问题(如果我没记错的话)

VIM uses multiple modes, to exit insert mode hit ESC or ^C. to save and exit the file use ZZ, :xor :wq

VIM 使用多种模式,退出插入模式按 ESC 或 ^C。保存并退出文件使用ZZ:x:wq

just to be complete: git commit -awill first add all tracked and changed files' contents to the index and then creates a commit (after specifying the commit message inside vim – or your editor of choice)

只是为了完成:git commit -a将首先将所有跟踪和更改的文件的内容添加到索引中,然后创建一个提交(在 vim 中指定提交消息后 – 或您选择的编辑器)

回答by asm

To save your commit you save and exit the file as you normally would in vim.

要保存您的提交,您可以像通常在 vim 中一样保存并退出文件。

:wq

If you change your mind and want to abort you exit without saving.

如果您改变主意并想中止,则不保存就退出。

:q!

You don't have to use VIM though, you can set the editor, for example the following would change the editor git uses to textmate.

不过,您不必使用 VIM,您可以设置编辑器,例如以下内容会将 git 使用的编辑器更改为 textmate。

git config --global core.editor textmate

回答by Herbert Sitz

As others have said, Vim is being opened so you an add a message with information about the changes you're committing. It seems the default editor on your system is Vim. Git is set up so that it will include whatever message you type and save in Vim, after you close Vim with :wq, :x, or some other command.

正如其他人所说,Vim 正在打开,因此您可以添加一条消息,其中包含有关您正在提交的更改的信息。您系统上的默认编辑器似乎是 Vim。Git 设置为在您使用 :wq、:x 或其他一些命令关闭 Vim 后,它将包含您键入并保存在 Vim 中的任何消息。

In addition to method Andrew Myers suggests of changing the editor being called by Git, you can include a simple message on the command line with something like this:

除了 Andrew Myers 建议更改 Git 调用的编辑器的方法之外,您还可以在命令行中包含一条简单的消息,如下所示:

git commit -am 'This is my message for the commit. . . '

If you do it that way Git will not bother you by opening a text editor at all.

如果你这样做,Git 根本不会打开文本编辑器来打扰你。