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

Re: Is git-checkout's restoring d/f conflict really sane?

From
Duy Nguyen <pclouds@gmail.com>
Date
May 14, 2019, 10:49 UTC
Message-ID
<CACsJy8DoxHoi0H3R91ovqDPjk0tN3Rr8fQOjaLt_2P9O3n9b_g@mail.gmail.com>
In-Reply-To
<xmqq8sv99vac.fsf@gitster-ct.c.googlers.com>
On Tue, May 14, 2019 at 5:37 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
>
> Duy Nguyen <pclouds@gmail.com> writes:
>
> > $ echo data > one
> > $ git add one
> > $ rm one
> > $ mkdir one
> > $ echo two > one/two
> > $ echo three > one/three
> > $ git checkout one
> > $ ls -l one
> > -rw-r--r-- 1 pclouds pclouds 5 May 14 16:36 one
> >
> > Replacing a file is one thing. In this case we're deleting a directory
> > and unknown number of files inside (in this case 'two' and 'three').
> > Is this really a good thing to do?
> >
> > If it's not but too late to do anything about git-checkout, could
> > git-restore do something better (and exactly what)?
>
> The user said "I do not want whatever I have under name 'one' in the
> working tree, and I want what I have as 'one' in the index instead",
> so I tend to think that failing the request would be a disservice.

Except that sometimes the user has those "oops that's not what I meant" moments (and I think it's more often "I want to restore _file_ 'one'"). One tricky thing in this situation is (to me) one/two and one/three are untracked and we generally do not touch them unless requested.

Technically 'one' is still tracked (even if it's a directory) so what we're doing is right. I'm just not sure if there's some big surprise factor here. And whether it's better to pause and double check with the user before deleting everything.

Show 5 quoted lines
> I suspect that this will become even more right thing to do, in the
> new world where the no-overlay mode becomes the default.  Unlike
> "checkout HEAD ."  that only adds to the set of paths in the working
> tree, "restore HEAD ." will remove what's in the working tree and in
> the index but not in the HEAD, no?

Yes. It makes me really want 'git restore --diff [--stat]' just to show what's going to be restored. A careful user may see something unexpected and examine more before really doing 'git restore'.

-- 
Duy
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 4 in “Is git-checkout's restoring d/f conflict really sane?”
  1. Duy NguyenMay 14, 2019
  2. Junio C HamanoMay 14, 2019
  3. Duy NguyenMay 14, 2019
  4. Junio C HamanoMay 15, 2019

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.