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

Re: way to automatically add untracked files?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Aug 5, 2007, 05:03 UTC
Message-ID
<alpine.LFD.0.999.0708042157150.5037@woody.linux-foundation.org>
In-Reply-To
<fc339e4a0708042100jdf0a0f1jd1fddfb5dc1c1052@mail.gmail.com>
On Sun, 5 Aug 2007, Miles Bader wrote:
Show 11 quoted lines
> I previously wrote
> > One thing I often want to do is git-add all untracked files, and also 
> > automatically git-rm all "disappeared" files
> ...
> > One way to do this seems to be just "git add ."
> 
> Oh, also, "git add ." doesn't seem to do the right thing with 
> "dissapeared" files:  If I do:
> 
>     mv foo.cc bar.cc
>     git add .
Do "git status -a" to figure out the removed ones.

I actually think we should probably make "git add ." do it too, but it's not how we've done it historically ("git add ." really ends up just reading the working directory tree and addign all the files it sees: so by definition it doesn't do anything at all to files it does *not* see, ie the removed ones).

> Am I doing something wrong, or is this just missing functionality?

Well, it's just "behaviour". It's probably largely historical, in that "git add" used to be thought of as "adding new files", but obviously then it got extended to mean "stage old files for commit" too, but in that extension, the "remove old files" never came up.

But git certainly has the capability. "git commit -a" will notice all the files that went away and automatically remove them, so

	git add .
	git commit -a

will do what you want (except, as we found out last week, we've had a huge performance regression, so that's actually a really slow way to do it, and so it's actually faster to do

	git ls-files -o | git update-index --add --stdin
	git commit -a

instead (where the first one just adds the *new* files, and then obviously the "git commit -a" does the right thing for old files, whether deleted or modified)

		Linus
Previous: Miles BaderNext: Junio C Hamano
Message 35 of 40 in “way to automatically add untracked files?”
  1. Miles BaderAug 5, 2007
  2. Shawn O. PearceAug 5, 2007
  3. Junio C HamanoAug 5, 2007
  4. Miles BaderAug 5, 2007
  5. Shawn O. PearceAug 5, 2007
  6. Miles BaderAug 5, 2007
  7. Junio C HamanoAug 5, 2007
  8. Miles BaderAug 5, 2007
  9. Junio C HamanoAug 5, 2007
  10. Miles BaderAug 5, 2007
  11. Junio C HamanoAug 5, 2007
  12. Miles BaderAug 5, 2007
  13. Johannes SchindelinAug 5, 2007
  14. Miles BaderAug 5, 2007
  15. Steffen ProhaskaAug 5, 2007
  16. Johan HerlandAug 5, 2007
  17. David KastrupAug 5, 2007
  18. Theodore TsoAug 5, 2007
  19. Johan HerlandAug 5, 2007
  20. Miles BaderAug 6, 2007
  21. Johannes SchindelinAug 6, 2007
  22. Miles BaderAug 6, 2007
  23. Johannes SchindelinAug 6, 2007
  24. Miles BaderAug 6, 2007
  25. Johan HerlandAug 6, 2007
  26. Johannes SchindelinAug 6, 2007
  27. Steffen ProhaskaAug 5, 2007
  28. Johannes SchindelinAug 6, 2007
  29. Steffen ProhaskaAug 6, 2007
  30. Jakub NarebskiAug 6, 2007
  31. Johan HerlandAug 6, 2007
  32. Junio C HamanoAug 6, 2007
  33. David KastrupAug 6, 2007
  34. Miles BaderAug 7, 2007
  35. Linus TorvaldsAug 5, 2007
  36. Junio C HamanoAug 5, 2007
  37. David KastrupAug 5, 2007
  38. Benchmarking git-add vs git-ls-files+update-index (was: way to automatically add untracked files?)David Kastrup, Aug 5, 2007
  39. Miles BaderAug 5, 2007
  40. Linus TorvaldsAug 5, 2007

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.