Dash Dash - 11 months ago 72
Git Question

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

I understand that the following command takes the text from standard input and uses it as the message for the commit log:

echo "hello world" | git commit -F -

But, if you just have it as
git commit -F -
then it brings you to what I call "standard input mode" where Git Bash displays the message
(reading log message from standard input)
and awaits some kind of input... I guess. My question is what is this mode really and can it be used at all? I've entered text and exited by using
, but had no luck in having the commit to run successfully afterwards. It would just bring me back to the prompt.

Question: What is actually going on in "standard input mode" and can it be used to enter the commit log message successfully?

EDIT: I've tried
, but nothing changes. I'm using Windows 10.

Answer Source

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

In order to use git commit -F - on Windows in the Git Bash console, you must append the command to winpty as so:

winpty git commit -F -

Afterwards, you will be taken to "standard input mode" as expected. Instead of using CTRL + D as you would with Linux and Mac, press CTRL + Z and then ENTER on a new line. This will indicate an EOF and save the commit log message.

If you press CTRL + Z on the same line as the message, then ^Z will be entered as text next to the message and nothing else will happen. You need to press CTRL + Z and then ENTER on a separate and empty line.

So, to edit blockloop's example:

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

Source: Github