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

Re: git-rm isn't the inverse action of git-add

From
Jeff King <peff@peff.net>
Date
Jul 3, 2007, 04:12 UTC
Message-ID
<20070703041241.GA4007@coredump.intra.peff.net>
In-Reply-To
<46896C3B.1050406@jaeger.mine.nu>
On Mon, Jul 02, 2007 at 11:20:59PM +0200, Christian Jaeger wrote:
> So there's no -f flag in normal git-rm usage. It thus has a different
> meaning, namely "force the operation pair of removing from index and
> unlinking", not "force this operation also onto the checked out files"
> as is the case with cogito.

Yes, git-rm is used in several situations, and the idea is that it should behave safely in all situations; that is, without -f you can't delete any data that can't be recovered from your history (but maybe that means we shouldn't suggest -f in so cavalier a fashion).

Each file has three "states" that we care about: in the HEAD (H), in the index (I), and in the working tree (W). Let's say you call 'git-rm'. Here's a table of possibilities (A is some content "A", B is some content not equal to "A", and N is "non-existant"):

H I W | ok? | why?
---------------------------------------------------
* N * | no  | file is not tracked
N A N | ?   | currently ok, but 'A' recoverable only through fsck
N A A | no  | 'A' recoverable only through fsck
N A B | no  | local modification 'B' would be lost
A A N | yes | 'A' recoverable through history
A A A | yes | 'A' recoverable through history
A A B | no  | local modification 'B' would be lost
A B N | ?   | currently ok, but 'B' recoverable only through fsck
A B A | no  | 'B' recoverable only through fsck
A B B | no  | 'B' recoverable only through fsck
B * * |     | equivalent to H=A
With --cached on, it is a little different:
H I W | ok? | why?
---------------------------------------------------
* N * | no  | file is not tracked
N A N |  ?  | currently ok, but 'A' recoverable only through fsck
N A A |  ?  | currently not ok, but 'A' still available in W
N A B | no  | 'A' recoverable only through fsck
A A N | yes | 'A' recoverable through history
A A A | yes | 'A' recoverable through history or working tree
A A B |  ?  | currently not ok, but 'A' still available in H
A B N |  ?  | currently ok, but 'B' recoverable only through fsck
A B A | no  | 'B' recoverable only through fsck
A B B |  ?  | currently not ok, but 'B' still available in W
B * * |     | equivalent to H=A

So it looks like our safety valve is a bit overbearing in a few situations, and still misses some situations where data has to be pulled out of the database with git-fsck.

I think if we actually spell out these possible states in the code, we can get more accurate behavior, but also more accurate error messages. I will try to work up a patch.

-Peff
Previous: Christian JaegerNext: Junio C Hamano
Message 29 of 37 in “git-rm isn't the inverse action of git-add”
  1. Christian JaegerJul 2, 2007
  2. Yann DirsonJul 2, 2007
  3. Christian JaegerJul 2, 2007
  4. Yann DirsonJul 2, 2007
  5. Matthieu MoyJul 2, 2007
  6. Johannes SchindelinJul 2, 2007
  7. Matthieu MoyJul 3, 2007
  8. Johannes SchindelinJul 3, 2007
  9. Matthieu MoyJul 3, 2007
  10. Johannes SchindelinJul 3, 2007
  11. Jan HudecJul 4, 2007
  12. Matthieu MoyJul 5, 2007
  13. David KastrupJul 5, 2007
  14. [RFC][PATCH] Re: git-rm isn't the inverse action of git-addMatthieu Moy, Jul 8, 2007
  15. Johannes SchindelinJul 8, 2007
  16. Matthieu MoyJul 8, 2007
  17. Johannes SchindelinJul 8, 2007
  18. Matthieu MoyJul 9, 2007
  19. Matthieu MoyJul 13, 2007
  20. More permissive "git-rm --cached" behavior without -f.Matthieu Moy, Jul 13, 2007
  21. Jeff KingJul 13, 2007
  22. Matthieu MoyJul 13, 2007
  23. Jeff KingJul 14, 2007
  24. Jakub NarebskiJul 14, 2007
  25. Junio C HamanoJul 14, 2007
  26. Junio C HamanoJul 14, 2007
  27. Matthieu MoyJul 14, 2007
  28. Christian JaegerJul 2, 2007
  29. Jeff KingJul 3, 2007
  30. Junio C HamanoJul 3, 2007
  31. Jeff KingJul 3, 2007
  32. Junio C HamanoJul 3, 2007
  33. Jeff KingJul 3, 2007
  34. Junio C HamanoJul 3, 2007
  35. Jakub NarebskiJul 11, 2007
  36. Jan HudecJul 11, 2007
  37. Junio C HamanoJul 11, 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.