1

The git documentation says that git rm command is to remove a file from the working directory and from the staged files.

I see that on doing rm some-file.txt, the file gets removed from the working directory. And on doing git add some-file.txt I can achieve the same results.

So, is git rm a convenience command?

Thanks :)

Andrejs Cainikovs
  • 27,428
  • 2
  • 75
  • 95
dhaliman
  • 1,542
  • 1
  • 12
  • 23
  • Thanks. Then git rm has to be convenience command. – dhaliman Jun 12 '17 at 09:03
  • No, it is not a convenience command. One can remove from index an already deleted file using `git add` but without `git rm` there is no direct way to remove a file only from index, while keeping it in the working tree. – axiac Jun 12 '17 at 09:12
  • 1
    @axiac: It *is* possible to remove a file from the index using only `git update-index`, but I'd sure prefer `git rm --cached` :-) – torek Jun 12 '17 at 13:52

1 Answers1

3

A bare git rm does exactly the same thing as what you did : rm the file from disk, git add file to reflect this modification in the index. In this sense, it is a convenience command.

However, this command allows you to do git rm --cached <file> (keep the version you have on disk, remove the version staged in index), which would require more shady manipulations to do by hand.

It also makes sure you are acting on tracked files, allows you to dry-run (-n) ...

LeGEC
  • 46,477
  • 5
  • 57
  • 104