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.
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`
Or, alternatively, on Windows Powershell:
git rm --cached $(git ls-files -i -X .gitignore)
If you want to just untrack a file and not delete from local and remote repo then use thhis command:
git update-index --assume-unchanged file_name_with_path
As per my Answer here: https://stackoverflow.com/questions/6313126/how-to-remove-a-directory-in-my-github-repository
Steps to remove directory
git rm -r --cached File-or-FolderName
git commit -m "Removed folder from repository"
git push origin master
Steps to ignore that folder in next commits
To ignore that folder from next commits make one file in root named .gitignore and put that folders name into it. You can put as many as you want
.gitignore file will be look like this
/FolderName
Git lets you ignore those files by assuming they are unchanged. This is done by running the
git update-index --assume-unchanged path/to/file.txt
command. Once marking a file as such, git will completely ignore any changes on that file; they will not show up when running git status or git diff, nor will they ever be committed.
(From https://help.github.com/articles/ignoring-files)
Hence, not deleting it, but ignoring changes to it forever. I think this only works locally, so co-workers can still see changes to it unless they run the same command as above. (Still need to verify this though.)
Note: This isn't answering the question directly, but is based on follow up questions in the comments of the other answers.
To remove an entire folder from the repo (like Resharper files), do this:
git rm -r --cached folderName
I had committed some resharper files, and did not want those to persist for other project users.