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

Re: (beginner) git rm

From
Björn Steinbrink <b.steinbrink@gmx.de>
Date
Jan 28, 2009, 22:13 UTC
Message-ID
<20090128221355.GE7503@atjola.homenet>
In-Reply-To
<7vab9bm85b.fsf@gitster.siamese.dyndns.org>
[Zabre, please keep the Cc: list when replying]
On 2009.01.28 13:29:36 -0800, Junio C Hamano wrote:
Show 31 quoted lines
> Zabre <427@free.fr> writes:
> > Björn Steinbrink wrote:
> >> 
> >> The "git checkout -- d.txt" is also a valid command, but that restores
> >> the file from the index.
> >> 
> >> git checkout -- paths
> >> 	==> Copy "paths" from the index to the working tree
> >> 
> >> git checkout <tree-ish> -- paths
> >> 	==> Copy "paths" from the tree-ish to the index and working tree
> >> 
> >> So, for "rm d.txt", a plain "git checkout -- d.txt" would also do the
> >> trick, as d.txt is still in the index. But your "git rm d.txt" also
> >> removed the file from the index, and thus that checkout does nothing.
> >> But "git checkout HEAD -- d.txt" works, as it gets the file from HEAD
> >> and puts it into the index and working tree.
> >
> > This is enlightening, thank you very much!
> > (I knew I would love git more and more)
> >
> > Oh just one (probably stupid) thing : <tree-ish> does represent a directory
> > being the root of a tree of folders (which has been added to the index),
> > does it?
> 
> Yeah, it typically is a commit object.
> 
> Björn said "Copy", but the operation really is like checking out a book
> from a library and "checkout" is a good word for it.  "I do not like what
> I have in my work tree, and I'd like to replace it with a fresh one taken
> out of the index (or, out of that commit)".

With "checkout", I'm still a bit unsure about which term to use, because of the behaviour you get with, for example, "git checkout HEAD -- directory". It always just adds or replaces files, but never removes them. So it's not really like taking the old directory out of the repo and using that instead. For example:

git rm dir/old_file echo 123 > dir/new_file git add dir/new_file git checkout HEAD -- dir

That won't remove dir/new_file from the index (and of course it won't drop it from the working tree). That's the one thing where "git checkout HEAD -- dir" differs from "git reset HEAD -- dir && git checkout -- dir". IIRC we've talked about that on #git a few months ago, but I don't recall what conclusions we came up with.

It would probably be better to say that checkout only works with the blobs (because the index doesn't have entries for trees, right?) that exist in the given tree-ish. And thus it doesn't remove entries from the index. But that feels a bit convoluted. :-/

Björn
Previous: Junio C HamanoNext: Junio C Hamano
Message 14 of 16 in “(beginner) git rm”
  1. ZabreJan 28, 2009
  2. Peter KreftingJan 28, 2009
  3. ZabreJan 28, 2009
  4. Tomas CarneckyJan 28, 2009
  5. ZabreJan 28, 2009
  6. Tomas CarneckyJan 28, 2009
  7. Theodore TsoJan 28, 2009
  8. ZabreJan 28, 2009
  9. ZabreJan 28, 2009
  10. Björn SteinbrinkJan 28, 2009
  11. ZabreJan 28, 2009
  12. ZabreJan 28, 2009
  13. Junio C HamanoJan 28, 2009
  14. Björn SteinbrinkJan 28, 2009
  15. Junio C HamanoJan 28, 2009
  16. Björn SteinbrinkJan 29, 2009

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.