"standard input mode" for `git commit -F -` in Git Bash for Windows 有什么用?

What's the use of "standard input mode" for `git commit -F -` in Git Bash for Windows?

我知道以下命令从标准输入中获取文本并将其用作提交日志的消息:

echo "hello world" | git commit -F -

但是,如果您只是将其设为 git commit -F -,那么它会将您带到我所说的 "standard input mode",其中 Git Bash 显示消息 (reading log message from standard input)并等待某种输入......我猜。我的问题是这种模式到底是什么,它真的可以使用吗?我已经输入文本并使用 ctrl-zctrl-c 退出,但之后没有成功提交到 运行。它只会让我回到提示。

问题:"standard input mode" 中实际发生了什么,是否可以用于成功输入提交日志消息?

编辑:我试过 ctrl-d,但没有任何改变。我正在使用 Windows 10.

输入消息后使用 CTRL-D (EOF)。 CTRL-C 终止,CTRL-Z 暂停。 EOF 告诉 STDIN 您的消息已完成。

git commit -F -
my message blah blah<enter>
<CTRL-D>

当您在命令中使用 - 时,它告诉应用程序从 STDIN 读取。 Git 注意到 STDIN 是空的(除非你先回显和管道)所以它开始监听输入。键入消息后,您必须通过发送 EOF 消息告诉它您已完成。 EOF 的组合键是 CTRL-D

当您 运行 echo hello | git commit -F - 将文本通过管道传输到 git 时,它会使用管道消息。

出于好奇,为什么不使用 git commit -m 'your message here'

When you use - in commands it tells the application to read from STDIN. Git notices that STDIN is empty (unless you echo and pipe first) so it starts listening for input. Once you type your message you have to tell it that you're finished by sending the EOF message.

When you run echo hello | git commit -F - you're piping text into git so it uses the piped message.

~ blockloop

为了在 Git Bash 控制台中的 Windows 上使用 git commit -F -,您必须将命令附加到 winpty,如下所示:

winpty git commit -F -

之后,您将按预期进入“标准输入模式”。而不是像使用 Linux 和 Mac 那样使用 CTRL + DCTRL + Z 然后在新行 ENTER。这将指示 EOF 并保存提交日志消息。

如果您在消息所在的同一行按 CTRL + Z,则 ^Z 将作为文本输入在消息旁边,不会发生其他任何事情。您需要按 CTRL + Z 然后在单独的空行上按 ENTER

因此,要编辑 blockloop 的示例:

winpty git commit -F -
my message blah blah<enter>
<CTRL-Z><enter>

来源:Github

您可以试试 SHIFT+esc ,然后输入 q 并按 Enter 。