0 votes
1 view
in Devops and Agile by (21.4k 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 (36.1k points)

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.