Stuck trying to commit

1,204 views
Skip to first unread message

Caleb Fong

unread,
Jun 29, 2016, 7:48:03 AM6/29/16
to git-for-windows
I accidentaly hit ctrl+z while writing a commit message and was sent back to the command prompt. How do I get back in to Vim and the commit message I was writing?

Paul Smith

unread,
Jun 29, 2016, 7:53:51 AM6/29/16
to Caleb Fong, git-for-windows
In UNIX you would type the command "fg".

C-z puts the current foreground process into the background and suspends it.  The "fg" (foreground) command takes the most-recently backgrounded process and brings it to the foreground again.

Don't know if Git for Windows works like that as well.

On Wed, Jun 29, 2016, 7:48 AM Caleb Fong <geekos...@gmail.com> wrote:
I accidentaly hit ctrl+z while writing a commit message and was sent back to the command prompt. How do I get back in to Vim and the commit message I was writing?

--
You received this message because you are subscribed to the Google Groups "git-for-windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to git-for-windo...@googlegroups.com.
To post to this group, send email to git-for...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/git-for-windows/67556eeb-64df-44fa-8409-dfa8f9580ada%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Konstantin Khomoutov

unread,
Jun 29, 2016, 8:30:58 AM6/29/16
to Caleb Fong, git-for-windows
Was that in Git Bash or in "normal" Windows shell?

The explanation is as follows. On POSIX (Unix-y) systems shells (and
otehr interactive non-GUI programs) run in terminals or terminal
emulators, and those Ctrl-z, Ctrl-c and similar keyboard combos are
usually handled by the terminal. What's more, POSIX shells support the
so-called job control -- having several processes spawned from the same
shell, of which a single one can be foreground, and any number of other
processes can run in background (or be stopped). Now in typical setups,
Ctrl-z makes terminal send a special signal (SIGSTP) to the foreground
process which a) suspends it; b) makes the shell put it into background
and show you its prompt again.

On Windows, shells do not support job control, and the console
driver does not handle Ctrl-z in any special way [*].
Because of this "native" Windows builds of Vim handle Ctrl-z themselves
and spawn *another* shell to mimic the Unix-y behaviour a bit: "when
the user hits Ctrl-z it gets the command prompt".

Contrary to this, the Vim build which comes packed with Git, and which
is run when you commit from Git Bash, makes a rather Unix-y combo with
Git Bash: when you hit Ctrl-z in Git Bash, that suspends the running Vim
instance and you get back to the Bash's prompt, with something like

[+] Stopped vim

printed above the prompt.

So, what to do next:

* If that has happened in Git Bash, type "fg" without double quotes and
hit Enter -- Vim will be unsuspended and brought to foreground
("fg" is a shell's job control command meaning just that: "bring
process to _f_ore_g_round").

* If that was native Vim build and you got a shell's prompt, quit it
by typing "exit" and hitting Enter -- you'll get back to Vim.

The first option is safer anyway so I'd try it first.

Note that you can use other job control commands in Git bash such as
"jobs" to enumerate attached processes, "bg" to make the process
backgrounded via Ctrl-z continue running in the background etc.

Caleb Fong

unread,
Jun 29, 2016, 4:07:50 PM6/29/16
to git-for-windows, geekos...@gmail.com
Thanks for the help all!

I was in Git Bash - sorry for not mentioning it in the original post.

While franticly er ... excitedly searching I did come across the `fg` command. I tried it ... but I think in my panic er ... excitement I issued other commands and `fg` didn't respond as expected.

I'm not sure what I did to have it not respond, but I have now tried the ctrl+z then fg and it's been fine. I'm sure I was doing something else weird.

In the end the thing that saved me was using 'git commit --amend' I had to wade through a couple other screens of messages but I was able to reopen the commit message and resolve my immediate problem.

I guess the main take away is to remember that Git Bash !=== any Windows text editor, and therefore will not do the expected action of 'ctrl+z'. Guess I need to re-print my Vim cheatsheet.

Konstantin Khomoutov

unread,
Jun 29, 2016, 4:27:08 PM6/29/16
to Caleb Fong, git-for-windows
On Wed, 29 Jun 2016 13:07:50 -0700 (PDT)
Caleb Fong <geekos...@gmail.com> wrote:

[...]
> I guess the main take away is to remember that Git Bash !=== any
> Windows text editor, and therefore will not do the expected action of
> 'ctrl+z'. Guess I need to re-print my Vim cheatsheet.

Well, you may just stick

source $VIMRUNTIME/mswin.vim

into your ~/.vimrc to have expected behaviour.

Do

:help mswin.vim

while in Vim to read more.

That thing is available in Vim bundled with GfW as well.


On a side note, it just occured to me I never tries to hit Ctrl-z while
in Vim edit mode -- it appears I got trained to undo "the Vim way" --
by returning into normal mode and issuing the u or U command.

Caleb Fong

unread,
Jun 29, 2016, 6:05:14 PM6/29/16
to git-for-windows
Oh! Good to know! Thanks Konstantin!

I will hold on to that tip, but put more focus on using vim as vim intended, since I also spend some time working with linux.
Reply all
Reply to author
Forward
0 new messages