Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

git rm command

git rm command

Git Basic OperationsGit Basic Operations


The git rm command is used to delete files.

If you simply delete a file manually from the working directory, running git status will show it under "Changes not staged for commit".

git rm has the following forms for deleting files:

1. Delete a file from the staging area and working directory:

git rm 

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

git rm runoob.txt 

If the file was modified before deletion and already placed in the staging area, you must use the force delete option -f.

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

git rm -f runoob.txt 

If you want to remove a file from the staging area but still keep it in the current working directory-in other words, just remove it from the tracking list-use the --cached option:

git rm --cached 

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

git rm --cached runoob.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 followed by a directory as a parameter, it will recursively delete all subdirectories and files in the entire directory:

git rm –r * 

Enter a directory and execute this statement to delete all files and subdirectories under that directory.


Git Basic OperationsGit Basic Operations