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

Re: Line ending normalization doesn't work as expected

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 4, 2017, 02:00 UTC
Message-ID
<xmqq8tgrhdt0.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<88c57b88-ef2c-d7db-15e2-12791d4cb201@web.de>
Torsten Bögershausen <tboegi@web.de> writes:
Show 10 quoted lines
>> $ git rm -r --cached . && git add .
>
> (Both should work)
>
> To be honest, from the documentation, I can't figure out the difference between
> $ git read-tree --empty
> and
> $ git rm -r --cached .
>
> Does anybody remember the discussion, why we ended up with read-tree ?

We used to use neither, and considered it fine to "rm .git/index" if you wanted to empty the on-disk index file in the old world. In the modern world, folks want you to avoid touching filesystem directly and instead want you to use Git tools, and the above are two obvious ways to do so.

"git read-tree" (without any parameter, i.e. "read these 0 trees and populate the index with it") and its modern and preferred synonym "git read-tree --empty" (i.e. "I am giving 0 trees and I know the sole effect of this command is to empty the index.") are more direct ways to express "I want the index emptied" between the two.

The other one, "git rm -r --cached .", in the end gives you the same state because it tells Git to "iterate over all the entries in the index, find the ones that match pathspec '.', and remove them from the index.". It is not wrong per-se, but conceptually it is a bit roundabout way to say that "I want the index emptied", I would think.

I wouldn't be surprised if the "rm -r --cached ." were a lot slower, due to the overhead of having to do the pathspec filtering that ends up to be a no-op, but there shouldn't be a difference in the end result.

Previous: Torsten BögershausenNext: Robert Dailey
Message 5 of 34 in “Line ending normalization doesn't work as expected”
  1. Robert DaileyOct 3, 2017
  2. Torsten BögershausenOct 3, 2017
  3. Robert DaileyOct 3, 2017
  4. Torsten BögershausenOct 3, 2017
  5. Junio C HamanoOct 4, 2017
  6. Robert DaileyOct 4, 2017
  7. Jonathan NiederOct 4, 2017
  8. Robert DaileyOct 4, 2017
  9. Junio C HamanoOct 5, 2017
  10. Jonathan NiederOct 5, 2017
  11. Torsten BögershausenOct 4, 2017
  12. Junio C HamanoOct 5, 2017
  13. Junio C HamanoOct 5, 2017
  14. Torsten BögershausenOct 5, 2017
  15. Junio C HamanoOct 6, 2017
  16. Torsten BögershausenOct 6, 2017
  17. 1/1 Introduce git add --renormalize .tboegi@web.de, Oct 16, 2017
  18. Junio C HamanoOct 16, 2017
  19. 1/1 Introduce git add --renormalize .tboegi@web.de, Oct 30, 2017
  20. Junio C HamanoNov 7, 2017
  21. Torsten BögershausenNov 7, 2017
  22. Junio C HamanoNov 8, 2017
  23. Torsten BögershausenNov 9, 2017
  24. Junio C HamanoNov 10, 2017
  25. Torsten BögershausenNov 12, 2017
  26. 1/1 Introduce git add --renormalize .tboegi@web.de, Nov 16, 2017
  27. Junio C HamanoNov 17, 2017
  28. Eric SunshineNov 17, 2017
  29. Junio C HamanoNov 18, 2017
  30. Robert DaileyFeb 15, 2018
  31. Junio C HamanoFeb 15, 2018
  32. Robert DaileyFeb 15, 2018
  33. Torsten BögershausenFeb 16, 2018
  34. Robert DaileyFeb 16, 2018

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.