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

Re: Untracked working tree files

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Oct 15, 2008, 19:56 UTC
Message-ID
<alpine.LFD.2.00.0810151247560.3288@nehalem.linux-foundation.org>
In-Reply-To
<alpine.DEB.1.10.0810151240220.7808@asgard.lang.hm>
On Wed, 15 Oct 2008, david@lang.hm wrote:
> 
> I see it fairly frequently when switching between different branches of a
> project.

So, at least for any normal switch, assuming file 'a' doesn't exist in the other branch, you really should have a few different cases:

 - you have a dirty file, and git should say something like
	error: You have local changes to 'file'; cannot switch branches.
   because it refuses to modify the file to match the other branch (which 
   includes removing it) if it doesn't match the index.
   So this case shouldn't leave anything behind.
 - You have that extra file, but it's not in the index.
   If it's in your current HEAD, we should still notice it with something 
   like:
	error: Untracked working tree file 'tree' would be removed by merge.
   because now it's untracked (not in the index), but the switching 
   between branches tries to essentially "apply" the difference between 
   your current HEAD and the new branch, and finds that the difference 
   involves removing a file that git isn't tracking.
See?
HOWEVER.

If you're used to doing "git checkout -f" or "git reset --hard", both of those checks are just ignored. After all, you asked for a forced switch.

And at least in the second case, what I think happens is that git won't remove the file it doesn't know about, so you'll have a "turd" left around.

So yes, you can certainly get these kinds of left-overs, but they really should be only happening if you "force" something. Do you do that often?

			Linus
Previous: david@lang.hmNext: david@lang.hm
Message 10 of 24 in “Untracked working tree files”
  1. Andrew MortonOct 15, 2008
  2. david@lang.hmOct 15, 2008
  3. david@lang.hmOct 15, 2008
  4. Andrew MortonOct 15, 2008
  5. Andrew MortonOct 15, 2008
  6. Nicolas PitreOct 15, 2008
  7. Nicolas PitreOct 15, 2008
  8. Linus TorvaldsOct 15, 2008
  9. david@lang.hmOct 15, 2008
  10. Linus TorvaldsOct 15, 2008
  11. david@lang.hmOct 15, 2008
  12. Andrew MortonOct 15, 2008
  13. Linus TorvaldsOct 15, 2008
  14. Andrew MortonOct 15, 2008
  15. Paolo CiarrocchiOct 16, 2008
  16. Andrew MortonOct 16, 2008
  17. Linus TorvaldsOct 15, 2008
  18. Andrew MortonOct 15, 2008
  19. Junio C HamanoOct 15, 2008
  20. reset --hard/read-tree --reset -u: remove unmerged new pathsJunio C Hamano, Oct 15, 2008
  21. Linus TorvaldsOct 15, 2008
  22. Junio C HamanoOct 16, 2008
  23. Ingo MolnarOct 16, 2008
  24. Junio C HamanoOct 16, 2008

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.