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, 20:17 UTC
Message-ID
<20090128201727.GD7503@atjola.homenet>
In-Reply-To
<1233166992184-2233892.post@n2.nabble.com>
On 2009.01.28 10:23:12 -0800, Zabre wrote:
Show 9 quoted lines
> Tomas Carnecky wrote:
> > 
> > Oops, sorry. git checkout HEAD -- d.txt
> > You have to tell which version of d.txt you want. In your case the 
> > version in HEAD.
> 
> Thank you for this precision, it makes me understand this command better.
> (Sorry for my late answer I've been unable to check my computer for a few
> hours)

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.

Björn
Previous: ZabreNext: Zabre
Message 10 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.