git rm command

Git Basic Operations


The git rm command is used to delete files.

If you simply manually delete files from the working directory, rungit statuswhenJustwill beChanges not staged for commitofHint。

The git rm command has the following forms for deleting files:

1. Delete files from both the staging area and the working directory:

git rm <file>

The following example deletes the example.txt file from both the staging area and the working directory:

git rm example.txt 

If the file was modified and staged before deletion, you must use the force deletion option.-f。

Force delete the modified example.txt file from both the staging area and the working directory:

git rm -f example.txt 

If you want to remove the file from the staging area but still keep it in the current working directory, in other words, only delete it from the tracking list, use--cachedJust select the option:

git rm --cached <file>

The following example deletes the example.txt file from the staging area:

git rm --cached example.txt

Example

Delete the hello.php file:

$ git rm hello.php 
rm 'hello.php'
$ ls
README

Remove the file from the staging area, but keep it in the working directory:

$ git rm --cached README 
rm 'README'
$ ls
README

You can delete recursively, that is, if a directory is given as an argument, it will recursively delete all subdirectories and files in the entire directory:

git rm –r * 

Enter a directory and execute this statement, and it will delete all files and subdirectories under that directory.



Git Basic Operations

other extensions