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/