Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (29.3k points)

My initial commit contained some log files. I've added *log to my .gitignore, and now I want to remove the log files from my repository.

git rm mylogfile.log

will remove a file from the repository, but will also remove it from the local file system.

How can I remove this file from the repo without deleting my local copy of the file?

1 Answer

0 votes
by (50.2k points)
edited by

For single file use this command

git rm --cached mylogfile.log

For single directory 

git rm  --cached -r mydirectory

As you are using 

git rm mylogfile.log 

use the above code that will help you to delete the file from a git repository without removing it in a local system.

--cached will remove from just the index but not allow you to delete the file on the local system.

For more information please go through the following tutorial to get more info about git:

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories