Category Archives: git

git QnA

Git: Remove a file from a Git repository without deleting it from the local filesystem

From: http://stackoverflow.com/questions/1143796/remove-a-file-from-a-git-repository-without-deleting-it-from-the-local-filesyste

git rm --cached mylogfile.log

For a directory:

git rm --cached -r mydirectory

You can also remove files from the repository based on your .gitignore without deleting them from the local file system :

git rm --cached `git ls-files -i -X .gitignore`

A more generic solution:

  1. Edit .gitignore file.ECHO mylogfile.log >> .gitignore
  2. Remove all items from index.git rm -r -f --cached .
  3. Rebuild index.git add .
  4. Make new commitgit commit -m "Removed mylogfile.log"