On SVN, removing something from the filesystem directly (rather than using svn) created a load of headaches.
I haven\'t found this to be an issue when using gi
Adding to Andy's answer, there is additional utility to git rm
:
Safety: When doing git rm
instead of rm
, Git will block the removal if there is a discrepancy between the HEAD
version of a file and the staging index or working tree version. This block is a safety mechanism to prevent removal of in-progress changes.
Safeguarding: git rm --dry-run
. This option is a safeguard that will execute the git rm
command but not actually delete the files. Instead it will output which files it would have removed.
Removing files using rm
is not a problem per se, but if you then want to commit that the file was removed, you will have to do a git rm
anyway, so you might as well do it that way right off the bat.
Also, depending on your shell, doing git rm
after having deleted the file, you will not get tab-completion so you'll have to spell out the path yourself, whereas if you git rm
while the file still exists, tab completion will work as normal.
git rm
will remove the file from the index and working directory ( only index if you used --cached
) so that the deletion is staged for next commit.
If you just use rm
, you will need to follow it up with git add <fileRemoved>
. git rm
does this in one step.
You can also use git rm --cached
which will remove the file from the index (staging it for deletion on the next commit), but keep your copy in the local file system.
Remove files from the index, or from the working tree and the index. git rm will not remove a file from just your working directory.
Here's how you might delete a file using rm -f
and then remove it from your index with git rm
$ rm -f index.html
$ git status -s
D index.html
$ git rm index.html
rm 'index.html'
$ git status -s
D index.html
However you can do this all in one go with just git rm
$ git status -s
$ git rm index.html
rm 'index.html'
$ ls
lib vendor
$ git status -s
D index.html
However, if you do end up using rm instead of git rm. You can skip the git add and directly commit the changes using:
git commit -a