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
Matthieu Moy <matthieu.moy@imag.fr>
Date
Jul 5, 2007, 13:44 UTC
Message-ID
<vpqd4z7q820.fsf@bauges.imag.fr>
In-Reply-To
<20070704200806.GA3991@efreet.light.src>
Jan Hudec <bulb@ucw.cz> writes:
Show 10 quoted lines
>> What's wrong with the behavior of "hg rm"?
>> What's wrong with the behavior of "svn rm"?
>> What's wrong with the behavior of "bzr rm"?
>> (no, I won't do it with CVS ;-) )
>> 
>> None of these commands have the problem that git-rm has.
>
> Hm. They all behave roughly the same: They unversion the file and unlink it,
> unless it is modified, in which case they unversion it and leave it
> alone.

Yes. Roughly, they'll ask you a --force flag whenever you'd risk data-loss. bzr gives you the choice between --force and --keep (that would be --cached in git) if the file doesn't match HEAD.

> Now git has the extra complexity that index contains also content of the
> file. But the behaviour can be easily adapted like this (HEAD = version in
> HEAD, index = version in index, tree = version in tree):
                                  ^^^^- I suppose you meant "version"
                                        here since you don't use
                                        "tree" after.
>  - if (HEAD == index && index == version) unversion and unlink
Just to be more precise:
   - if (HEAD == index && index == version) unversion and
       * if (--cached is not given) unlink
       * else do nothing
>  - else if (HEAD == index || index == version) unversion
>  - else print message and do nothing
>
> Would you consider that a sane behaviour?
To me, that's a sane behavior.
It makes a few senarios easy and safe, like this:
  $ git add <whatever>
  # Ooops, no, I didn't want to version this one :-(
  $ git rm some-file
  # Cool, I just cancelled my mistake without loosing anything ;-)
  
One benefit is: you don't have to use "-f" for a non-dangerous
senario. That seems stupid, but for the plain "rm" command, the "-rf"
is hardcoded in the fingers of many unix users, and I know several
people having lost data by typing it a bit too mechanically (with a
typo behind, like forgetting the "*" in "*~" ;-).

I'll try writting patch for that if people agree that this is saner that the current behavior.

-- 
Matthieu
Previous: Jan HudecNext: David Kastrup
Message 12 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.