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

Re: Bug report: `git restore --source --staged` deals poorly with sparse-checkout

From
Victoria Dye <vdye@github.com>
Date
Oct 5, 2022, 16:11 UTC
Message-ID
<85def494-46c5-3785-8c78-31a733ab72e0@github.com>
In-Reply-To
<CAESOdVByucFm=yJn2yL1mwKGqey7tHXH4A-JM-yP125Ok+_Q+g@mail.gmail.com>
Martin von Zweigbergk wrote:>>>> Theoretically, 'restore' (like 'checkout') should be limited to pathspecs
Show 16 quoted lines
>>>> inside the sparse-checkout patterns (per the documentation of
>>>> '--ignore-skip-worktree-bits'), but 'Documentation' does not match them.
>>>> Then, there's a difference between 'restore' and 'checkout' that doesn't
>>>> seem intentional; both remove the 'SKIP_WORKTREE' flag from the file, but
>>>> only 'checkout' creates the file on-disk (therefore avoiding the "deleted"
>>>> status).
>>>
>>> Restoring only into the index (as I think `git restore --staged` is supposed
>>> to do) is weird.
>>
>> 'git restore --staged' is intended to restore to both the worktree and index
>> (per 183fb44fd2 (restore: add --worktree and --staged, 2019-04-25)). The bug
>> you've identified is that it's not restoring to the worktree.
> 
> Ah, `--worktree` is on by default even if I pass `--staged`, I see. Hmm, the
> help text actually says "Specifying --staged will only restore the index."...

You (and Elijah [1]) are correct. '--staged' overrides the "checkout to worktree" default behavior of 'git restore' to only restore to the index. If you want to checkout to the worktree _and_ the index, 'git restore --staged --worktree' is what you'd use.

Sorry for the incorrect information! 
[1] https://lore.kernel.org/git/CABPp-BGeC3hXw-v3voniY5ZU2f6W8NXfXVvq0C03eGGhvSefgg@mail.gmail.com/
Previous: Elijah NewrenNext: Elijah Newren
Message 8 of 12 in “Bug report: `git restore --source --staged` deals poorly with sparse-checkout”
  1. Glen ChooOct 3, 2022
  2. Victoria DyeOct 4, 2022
  3. Victoria DyeOct 4, 2022
  4. Martin von ZweigbergkOct 5, 2022
  5. Elijah NewrenOct 5, 2022
  6. Martin von ZweigbergkOct 5, 2022
  7. Elijah NewrenOct 6, 2022
  8. Victoria DyeOct 5, 2022
  9. Elijah NewrenOct 5, 2022
  10. Junio C HamanoOct 6, 2022
  11. Junio C HamanoOct 6, 2022
  12. Elijah NewrenOct 5, 2022

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.