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 17, 2013, 20:10 UTC
Message-ID
<20130917201003.GA16860@sigill.intra.peff.net>
In-Reply-To
<20130917190659.GA15588@pengutronix.de>
On Tue, Sep 17, 2013 at 09:06:59PM +0200, Uwe Kleine-König wrote:
> 	$ git checkout HEAD^ -- subdir
> 
> I'd expect that subdir/b is removed from the index as this file didn't
> exist in HEAD^ but git-status only reports:

I'm not sure if this is intentional or not. The definition of "git checkout $tree $path" given in commit 0a1283b says:

    Checking paths out of a tree is (currently) defined to do:
     - Grab the paths from the named tree that match the given pathspec,
       and add them to the index;
     - Check out the contents from the index for paths that match the
       pathspec to the working tree; and while at it
     - If the given pathspec did not match anything, suspect a typo from the
       command line and error out without updating the index nor the working
       tree.

So we are applying the pathspec to the named tree, and pulling anything that matches into the index. Which by definition cannot involve a deletion, because there is no comparison happening (so we either have it, or we do not). Whereas what you are expecting is to compare the tree and the index, limited by the pathspec, and pull any changes from the tree into the index.

I tend to agree that the latter is more like how other git commands behave (e.g., if you tried to use "read-tree" to emulate what git-checkout was doing, I think you would end up with a two-way merge). But there may be implications I haven't thought of.

Note also that "git checkout -p" does present "subdir/b" as a deletion. It works by doing a pathspec-limited diff between the two endpoints, which will notice deletions. So there is some inconsistency there with the baseline form.

-Peff
Previous: Junio C Hamano
Message 15 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.