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?
As per my Answer here: https://stackoverflow.com/questions/6313126/how-to-remove-a-directory-in-my-github-repository
To remove folder/directory or file only from git repository and not from the local try 3 simple steps.
Steps to remove directory
Steps to ignore that folder in next commits
.gitignore file will be look like this
Above answers didn't work for me. I used filter-branch to remove all committed files
remove a file from a git repository with:
remove a folder from a git repository with:
This removes the directory or file from all the commits
you can specify a commit by using:
Or an range
To push everything to remote, you can do:
To remove an entire folder from the repo (like Resharper files), do this:
I had committed some resharper files, and did not want those to persist for other project users.
A more generic solution:
Edit
.gitignore
file.ECHO mylogfile.log >> .gitignore
Remove all items from index.
git rm -r -f --cached .
Rebuild index.
git add .
Make new commit
git commit -m "Removed mylogfile.log"
If you want to just untrack a file and not delete from local and remote repo then use thhis command:
Also, if you have commited sensitive data (e.g. a file containing passwords), you should completely delete it from the history of the repository. Here's a guide explaining how to do that: http://help.github.com/remove-sensitive-data/