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

Re: undoing changes with git-checkout -f

From
Llamikr <lamikr@cc.jyu.fi>
Date
Jan 9, 2006, 22:36 UTC
Message-ID
<43C2E566.2060006@cc.jyu.fi>
In-Reply-To
<Pine.LNX.4.64.0601091321390.5588@g5.osdl.org>
Linus Torvalds wrote:
Show 15 quoted lines
>You should realize that git _does_not_know_ about your file. You never 
>even told git about it. So git won't ever evenlook at it, much less delete 
>it.
>
>So when you do a "git checkout -f", what that does is to rewrite all the 
>files that git KNOWS about. Any files git doesn't know about will not ever 
>be touched. Your "1.txt" file might as well be an object file, for all git 
>knows. And git won't remove your object files or any other files that it 
>doesn't know.
>
>(Now, in all fairness, even if you had done "git add", I don't think git 
>will remove the file. If you committed the file and then checked out the 
>previous version, _then_ it would remove the committed file).
>  
>

Now that you say it, I got it, thanks. I expected earlier that git would perform also the remove of non-added files as other commands like "git-commit" are anyway aware if you have files in your working dir that have not yet added.

Show 6 quoted lines
>If what you want to do is to clean the git directory of all files that git 
>doesn't know about, you can do that with
>
>	git-ls-files -z --others | xargs -0 rm --
>  
>

Thanks for the tip. I have now added alias git-reset-ff='git-ls-files -z --others | xargs -0 rm --' And git-reset-fff (forte fortissimo) would probably blow the whole hd away :-)

Mika
Previous: Alex Riesen
Message 14 of 14 in “undoing changes with git-checkout -f”
  1. lamikrJan 9, 2006
  2. Junio C HamanoJan 9, 2006
  3. lamikrJan 9, 2006
  4. Joel BeckerJan 10, 2006
  5. Junio C HamanoJan 10, 2006
  6. Joel BeckerJan 10, 2006
  7. Joel BeckerJan 10, 2006
  8. Junio C HamanoJan 10, 2006
  9. Joel BeckerJan 10, 2006
  10. Johannes SchindelinJan 10, 2006
  11. Alex RiesenJan 10, 2006
  12. Johannes SchindelinJan 10, 2006
  13. Alex RiesenJan 10, 2006
  14. lamikrJan 9, 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.