Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I git rm a file without deleting it from disk? [duplicate]

Tags:

git

git-rm

The command removes the file in my system. I meant it to remove only the file from Git-repository.

How can I remove the file from a Git repository, without removing the file in my system?

like image 559
Léo Léopold Hertz 준영 Avatar asked Aug 13 '09 16:08

Léo Léopold Hertz 준영


People also ask

Does git rm actually delete the file?

By default, the git rm command deletes files both from the Git repository as well as the filesystem. Using the --cached flag, the actual file on disk will not be deleted.

Why does git rm delete the file?

Git rm Overview The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory. There is no option to remove a file from only the working directory.

How do I remove a file from a git repository?

The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.


2 Answers

git rm --cached file 

should do what you want.

You can read more details at git help rm

like image 179
kwatford Avatar answered Sep 18 '22 20:09

kwatford


I tried experimenting with the answers given. My personal finding came out to be:

git rm -r --cached . 

And then

git add . 

This seemed to make my working directory nice and clean. You can put your fileName in place of the dot.

like image 23
gran_profaci Avatar answered Sep 20 '22 20:09

gran_profaci