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

Re: bug report: git checkout deletes worktree file even though it is excluded by sparse-checkout

From
Elijah Newren <newren@gmail.com>
Date
May 28, 2021, 22:44 UTC
Message-ID
<CABPp-BGUxHiYLjVcqBc0qpaHpd5MZCN_6S0YpH8tKcP3GSV2Pw@mail.gmail.com>
In-Reply-To
<F58C0A40-A1B4-4B47-A8EA-20FEAB011B0D@botech.co.uk>
Hi,

On Fri, May 28, 2021 at 1:46 PM Tim Renouf (open source) <tpr.ll@botech.co.uk> wrote:

Show 43 quoted lines
>
> Hi all
>
> I have a bug report: git checkout deletes a worktree file even though it is excluded by sparse-checkout, even if it is dirty.
>
> Watch this (starting in an empty directory):
>
> $ git init
> Initialised empty Git repository in /mnt/amd/home/trenouf/amd/tmp/git/.git/
> $ echo file1 >file1; echo file2 >file2
> $ git add file1 file2
> $ git commit -m"commit 1"
> [master (root-commit) 4f7035d] commit 1
>  2 files changed, 2 insertions(+)
>  create mode 100644 file1
>  create mode 100644 file2
> $ git rm file2
> rm 'file2'
> $ git commit -m"rm file2"
> [master d025c99] rm file2
>  1 file changed, 1 deletion(-)
>  delete mode 100644 file2
> $ git checkout master~1
> HEAD is now at 4f7035d commit 1
> $ git sparse-checkout set /file1
> $ ls
> file1
> $ echo dirty >file2
> $ ls
> file1  file2
> $ git checkout master
> Previous HEAD position was 4f7035d commit 1
> Switched to branch 'master'
> $ ls
> file1
>
> I set up sparse-checkout to include only file1, not file2. file2 is now not in the worktree, even though it is in the commit I am checked out at. Then I create file2 with arbitrary content. Then a git checkout switching to the commit where file2 is removed also deletes it from the worktree.
>
> I assert that file2 should be left untouched by that checkout, because it is excluded by sparse-checkout. I guess file2 had its skip-worktree bit set before the checkout that removed it from the index; that should stop it being deleted in the worktree.
>
> To be clear, I expect that last “ls” to still show “file1  file2”.
>
> Thank you for your attention if you have got this far.

Thanks for the report. It's another example of how "skip-worktree-means-treat-the-file-as-matching-head" causes confusion. You can find more issues with present-despite-skip-worktree files at https://lore.kernel.org/git/CABPp-BF6GpoDtMfpzf=3VWL_puuRH-cNV=9KajdF1003Fe05jA@mail.gmail.com/, including reasons they come up more often than you'd think.

We do need to get these fixed up, though I don't want to step on Stolee's toes with his sparse-index work, and I'm hesitant to open new big projects until merge-ort is complete.

Show 14 quoted lines
> -tpr
>
> [System Info]
> git version:
> git version 2.31.1
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Linux 5.8.0-53-generic #60~20.04.1-Ubuntu SMP Thu May 6 09:52:46 UTC 2021 x86_64
> compiler info: gnuc: 9.3
> libc info: glibc: 2.31
> $SHELL (typically, interactive shell): /bin/bash
Previous: Tim Renouf (open source)Next: Tim Renouf
Message 2 of 10 in “bug report: git checkout deletes worktree file even though it is excluded by sparse-checkout”
  1. Tim Renouf (open source)May 28, 2021
  2. Elijah NewrenMay 28, 2021
  3. unpack-trees: add core.sparseCheckoutRmFiles configTim Renouf, Jun 1, 2021
  4. Derrick StoleeJun 2, 2021
  5. Junio C HamanoJun 2, 2021
  6. Elijah NewrenJun 2, 2021
  7. Tim Renouf (open source)Jun 2, 2021
  8. Elijah NewrenJun 2, 2021
  9. Tim Renouf (open source)Jun 5, 2021
  10. Derrick StoleeJun 2, 2021

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.