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

Re: [BUG?] git checkout $commit -- somedir doesn't drop files

From
Jeff King <peff@peff.net>
Date
Sep 19, 2013, 07:46 UTC
Message-ID
<20130919074616.GA29773@sigill.intra.peff.net>
In-Reply-To
<xmqqd2o7w0xc.fsf@gitster.dls.corp.google.com>
On Tue, Sep 17, 2013 at 03:14:39PM -0700, Junio C Hamano wrote:
Show 11 quoted lines
> Yeah, then I agree that "git checkout HEAD^ -- subdir" should be a
> one-way "go HEAD^" merge limited only to the paths that match
> subdir/.
> 
> If implemented in a straight-forward way, I suspect that we may end
> up not removing subdir/b in Uwe's sample transcript. I am not sure
> if that is a good thing or not, though.  If the index originally
> tracked and then "going to" tree does not, I think removing it would
> match "ignore local modifications" rule, as subdir/a that is tracked
> in the index and also in "going to" tree does get overwritten to
> match the state recorded in the tree.

I had assumed the goal was to subdir/b (by the reasoning above, and the "rm -rf && tar" analogy you gave earlier).

I tried a very hacky attempt at shoving unpack-trees into the right spot in checkout_paths. But its pathspec handling from unpack_trees is not quite what we want.

In Uwe's case, it did delete subdir/b and overwrite subdir/a, which I'd expect. But if there was an additional file outside of subdir, it got deleted, too. The problem is that I was giving the regular index to unpack_trees as the destination; so it wrote out only the bits of the index under the pathspec subdir/, and omitted the rest entirely. I had hoped instead it would leave those parts untouched from the source.

An alternative would be to write the new entries to a temporary index in memory. And then you can throw away the entries in the current index that match the pathspec, and add in the entries from the temporary index. I was just hoping that unpack-trees would do all of that for me. :)

At this point, I'm giving up for now. I was hoping a naive application of unpack-trees would just work (and reduce the code size to boot), but it is obviously a bit more complicated than that. I still think it's a good idea for checkout to behave as Uwe described, but I don't think it's that high a priority, and I have other stuff I'd prefer to work on at the moment.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 of 15 in “[BUG?] git checkout $commit -- somedir doesn't drop files”
  1. Uwe Kleine-KönigSep 17, 2013
  2. Junio C HamanoSep 17, 2013
  3. Jeff KingSep 17, 2013
  4. Junio C HamanoSep 17, 2013
  5. Jeff KingSep 17, 2013
  6. Junio C HamanoSep 17, 2013
  7. Jeff KingSep 17, 2013
  8. Junio C HamanoSep 17, 2013
  9. Jeff KingSep 17, 2013
  10. Junio C HamanoSep 17, 2013
  11. Jeff KingSep 19, 2013
  12. Junio C HamanoSep 19, 2013
  13. Jeff KingSep 19, 2013
  14. Junio C HamanoSep 20, 2013
  15. Jeff KingSep 17, 2013

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.