In my personal git repo, I have a directory that contains thousands of small images that are no longer needed. Is there a way to delete them from the entire git history? I have tried
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch imgs" HEAD
and
git filter-branch --tree-filter 'rm -fr imgs' HEAD
but the size of the git repo remains unchanged. Any ideas?
Thanks
Just run the rm command with the -f and -r switch to recursively remove the . git folder and all of the files and folders it contains. This Git repo remove command also allows you to delete the Git repo while allowing all of the other files and folder to remain untouched.
The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.
Delete a Directory ( rm -r ) To delete (i.e. remove) a directory and all the sub-directories and files that it contains, navigate to its parent directory, and then use the command rm -r followed by the name of the directory you want to delete (e.g. rm -r directory-name ).
The ProGit book has an interesting section on Removing Object.
It does end with this:
Your history no longer contains a reference to that file.
However, yourreflog
and a new set of refs that Git added when you did thefilter-branch
under.git/refs/original
still do, so you have to remove them and then repack the database. You need to get rid of anything that has a pointer to those old commits before you repack:
$ rm -Rf .git/refs/original $ rm -Rf .git/logs/ $ git gc $ git prune --expire
(git prune --expire
is not mandatory but can remove the directory content from the loose objects)
Backup everything before doing those commands, just in case ;)
Actually none of these techniques workedfor me. I found the most reliable was was to simply pull locally into another repo:
git pull file://$(pwd)/myGitRepo
It also saves you the hassle of deletig old tags.
see the story on my blog: http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
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