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

Re: [RFC] git checkout $tree -- $path always rewrites files

From
Jeff King <peff@peff.net>
Date
Nov 8, 2014, 08:45 UTC
Message-ID
<20141108084526.GA18912@peff.net>
In-Reply-To
<20141108083040.GA15833@peff.net>
On Sat, Nov 08, 2014 at 03:30:40AM -0500, Jeff King wrote:
Show 15 quoted lines
> So just to be clear, the behavior we want is that:
> 
>   echo foo >some-new-path
>   git add some-new-path
>   git checkout HEAD -- .
> 
> will delete some-new-path (whereas the current code turns it into an
> untracked file). What should:
> 
>   git checkout HEAD -- some-new-path
> 
> do in that case? With the current code, it actually barfs, complaining
> that nothing matched some-new-path (because it is not part of HEAD, and
> therefore we don't consider it at all), and aborts the whole operation.
> I think we would want to delete some-new-path in that case, too.
Also, t2022.3 has me very confused.

It is explicitly checking that if we have "subdir/foo" unmerged in the index, and we "git checkout $tree -- subdir", and $tree does not mention "foo", that we _leave_ foo in place.

That seems very counter-intuitive to me. If you asked to make "subdir" look like $tree, then we should clobber it. That change comes from e721c15 (checkout: avoid unnecessary match_pathspec calls, 2013-03-27), where it is mentioned as a _bugfix_. That in turn references 0a1283b (checkout $tree $path: do not clobber local changes in $path not in $tree, 2011-09-30), which explicitly goes against the goal we are talking about here. It is not "make my index and working tree look like $tree" at all.

So now I'm doubly confused about what we want to do.

If we want to retain that behavior, I think we can still cover these cases by marking items missing from $tree as "to remove" during the diff/"update the index" phase, and then being more gentle with "to remove" files (e.g., not clobbering changed worktree files unless "-f" is given).

I am not sure that provides a sane user experience, though. Why is it OK to clobber local changes to a file if we are replacing it with other content, but _not_ if we are replacing it with nothing? Either the content we are losing is valuable or not, but it has nothing to do with what we are replacing. And Junio argued in the thread linked elsewhere that the point of "git checkout $tree -- $path" is to clobber what is in $path, which I would agree with.

I think the argument made in 0a1283b is that "git checkout $tree $path" is not "make $path like $tree", but rather "pick bits of $path out of $tree". Which would mean this whole deletion thing we are talking about is completely contrary to that.

So which is it?
-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 11 of 23 in “[RFC] git checkout $tree -- $path always rewrites files”
  1. Jeff KingNov 7, 2014
  2. Jeff KingNov 7, 2014
  3. Duy NguyenNov 7, 2014
  4. Junio C HamanoNov 7, 2014
  5. Jeff KingNov 7, 2014
  6. Junio C HamanoNov 7, 2014
  7. Jeff KingNov 7, 2014
  8. Martin von ZweigbergkNov 8, 2014
  9. Martin von ZweigbergkNov 8, 2014
  10. Jeff KingNov 8, 2014
  11. Jeff KingNov 8, 2014
  12. Junio C HamanoNov 9, 2014
  13. Martin von ZweigbergkNov 8, 2014
  14. Jeff KingNov 9, 2014
  15. Junio C HamanoNov 9, 2014
  16. Jeff KingNov 13, 2014
  17. Junio C HamanoNov 13, 2014
  18. Jeff KingNov 13, 2014
  19. Jeff KingNov 13, 2014
  20. Junio C HamanoNov 13, 2014
  21. Jeff KingNov 13, 2014
  22. David AguilarNov 14, 2014
  23. Junio C HamanoNov 14, 2014

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.