I've been accidentally including my Python virtual environment directory venv
in all my git commit and push activity.
I've just added venv
to my .gitignore
. But my .git folder is still massive (I'm assuming because of the previous commits and tracking of venv).
How can I get git to totally forget about tracking venv
and get my .git
folder down to a reasonable size again as it's making Heroku pushes a nightmare.
Try deleting the files from your git repository:
git rm --cached venv*
Rich Stone mentions below, that if venv
is a folder, you should use the recursive switch, -r
:
git rm --cached -r venv*
Try git gc
, according to the manual this triggers an automatic garbage collection. If this doesn't help, leave a comment here and I'll investigate further options for you.
No, it does not. .gitignore
only ensures that ignored files aren't accidentally added, but it does not delete them from history, nor from HEAD, nor even from the index if they've already been added.
To permanently delete large files from git history requires history rewriting, which is a somewhat painful operation. In particular, it breaks pushes and pulls from other repositories that have the "old" version of the history. But it can be done; see e.g. this question or this one for details.
See this thread: How to make Git "forget" about a file that was tracked but is now in .gitignore?
It is easy to get the files out of the current commit, but removing them from the history entirely to get your file size down is a mess, see How to remove/delete a large file from commit history in Git repository? or https://help.github.com/articles/remove-sensitive-data
It might be faster to just export your latest code to a new git repo and start over and keep the old one for an archive.
Putting a file in .gitignore
doesn't remove the file from the repository.
You need to use git filter-brach
to completely remove a file or directory from the repository. To do this, use the following commands:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch file/or/dir/with/complete/path' --prune-empty --all
WIth this, you will change the repository history to complete remove file/or/dir/with/complete/path
from all commits. Remember that you will need to perform a git push -f
because you changed the history.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With