what does git rm do as opposed to deleting by OS and git add

1k Views Asked by At

If we want to delete a file (say file1.txt) and stop the git repo to track it, it is said that we should use git rm file1.txt and then git commit -m "..." it. But deleting from the working directory by OS, rm file1.txt, add . and then git commit -m "..." do the same. what are their difference?

2

There are 2 best solutions below

0
jthill On

There's no difference. git add of a tracked file you've removed from the work tree removes the index entry. A tracked file is what's in the work tree and the index record for it, there's nothing else, your sequence is exactly git rm.

1
Heirloom On

By default, the git rm command deletes files both from the Git repository as well as the filesystem.

Deleting it manually using rm (file), won't remove it from the Git repo unless you do the following (after deleting that file):

git add *

git commit -m