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

Re: On removing files and "git-rm is pointless"

From
Linus Torvalds <torvalds@osdl.org>
Date
Dec 4, 2006, 15:42 UTC
Message-ID
<Pine.LNX.4.64.0612040737120.3476@woody.osdl.org>
In-Reply-To
<7vd570q888.fsf@assigned-by-dhcp.cox.net>
On Mon, 4 Dec 2006, Junio C Hamano wrote:
> 
> FWIW, I too am in favor of the proposed fix to "git rm" as Linus
> outlined.

Note that somebody (sorry, forget who) correctly pointed out that in order to be "safe", the file that you "rm" has to match not only the index, but it should match the HEAD tree too.

If it matches both the index and the HEAD tree, a "git rm filename" is totally safe, since you can always get it back by just doing a

	git checkout HEAD filename

so the "git rm" really didn't lose any info, and as such, we can _happily_ remove the working tree copy without any concern at all.

If it doesn't match HEAD, we can't get it back as easily, so maybe that's the case when we want to have "git rm -f filename".

(And obviously, for all the normal reasons, if the index or HEAD doesn't match, the error message should be helpful and also explicitly mention the "-f" flag. Somehing like

	file 'x' does not match HEAD or has been staged for changes.
	Will not remove. Use '-f' to force removal.

("has been staged for changes" is just a long way of saying "index". See? I _can_ learn.)

Previous: Jakub NarebskiNext: Jakub Narebski
Message 7 of 13 in “On removing files and "git-rm is pointless"”
  1. Carl WorthDec 2, 2006
  2. Linus TorvaldsDec 2, 2006
  3. Sam VilainDec 2, 2006
  4. Nicolas PitreDec 3, 2006
  5. Junio C HamanoDec 4, 2006
  6. Jakub NarebskiDec 4, 2006
  7. Linus TorvaldsDec 4, 2006
  8. Jakub NarebskiDec 4, 2006
  9. Olivier GalibertDec 4, 2006
  10. Junio C HamanoDec 5, 2006
  11. Nicolas PitreDec 5, 2006
  12. Carl WorthDec 5, 2006
  13. Junio C HamanoDec 5, 2006

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.