git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 16, 2023, 01:15 UTC
Message-ID
<xmqqedl8lkqu.fsf@gitster.g>
In-Reply-To
<ZLM4sTUjBQt4QMfG@tapette.crustytoothpaste.net>
"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 13 quoted lines
>> When the user presses Ctrl-C, the correct action would be to cleanly return
>> to the initial branch.
>
> I would disagree here.  When the user has hit Ctrl-C, they want to
> interrupt the operation.  That's literally why a SIGINT (interrupt)
> signal is sent.  A checkout can take a long time, and the user will not
> want Git to perform an operation which will take even longer than the
> original one (because the original checkout was aborted).
>
> Even if we did that, the user could just hit Ctrl-C again and really
> interrupt the process, and then they'd be stuck again.
>
> If you don't want to interrupt the operation, then don't hit Ctrl-C.

I agree with all of the above, but stopping with "don't" is not very helpful---people do do things that they are told not to anyway, and it makes a whole lot of difference if they know how to recover from the fallout of their actions. It would help to teach "reset --hard" or something that lets the user to return to a known state. It may not necessarily be the state the user would want to go, but it is still better to be in a known stable state and be able to complain "I lost my stashed changes" or "I lost a few commits" than to be in a state where the user is totally lost and do not know what to do next.

Of course, that kind of coaching is not something we should do in our error or advise messages, but in an early part of the tutorial or somewhere, perhaps?

Thanks.
Previous: brian m. carlsonNext: Yuri
Message 3 of 6 in “Pressing Ctrl-C during 'git checkout <branch-name>' messes up the repository”
  1. YuriJul 15, 2023
  2. brian m. carlsonJul 16, 2023
  3. Junio C HamanoJul 16, 2023
  4. YuriJul 17, 2023
  5. Konstantin KhomoutovJul 17, 2023
  6. Andreas SchwabJul 17, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.