Does git remove files from version control after adding them to .gitignore?

I accidentally included my Python virtual environment directory venv

in all my git commit and push actions.

I just added venv

to mine .gitignore

. But my .git folder is still massive (I assume due to previous commits and venv tracking).

How can I get git to completely forget about tracking venv

and get my folder back .git

to a reasonable size again as it makes Heroku push a nightmare.

+3


source to share


5 answers


Try to remove files from the git repository:



$> git rm --cached venv*

      

+2


source


See this thread: How do I make Git "forget" about a file that was tracked but is now in .gitignore?

It's easy to get files from the current commit, but to completely remove them from history to get your file size is a mess, see How do I remove / remove a large file from the commit history in a Git repository? or https://help.github.com/articles/remove-sensitive-data



You can most likely just export your latest code to a new Git repository and start over and keep the old one for the archive.

+1


source


Try it git gc

, according to the manual it triggers automatic garbage collection. If that doesn't help, please post a comment here and I'll explore additional options for you.

0


source


No, it is not. .gitignore

ensures that ignored files are not accidentally added, but does not remove them from history, neither from the HEAD, nor even from the index if they are already added.

To permanently remove large files from git, history requires history rewriting, which is a somewhat painful operation. In particular, it breaks pushes and pulls from other repos that have an "old" version of history. But it can be done; see for example this question or this one .

0


source


Putting the file in .gitignore

does not 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

      

In this case, you will change the repository history to complete the deletion file/or/dir/with/complete/path

from all commits. Remember, you will need to follow through git push -f

because you changed the story.

0


source







All Articles