Assume, at the 1 February we have Git repository with size 5 MB. After adding some images and committing them to 10 February we receive repo with 15 MB.
How to remove this images from repo and decrease size to 5 MB?
Assume, at the 1 February we have Git repository with size 5 MB. After adding some images and committing them to 10 February we receive repo with 15 MB.
How to remove this images from repo and decrease size to 5 MB?
The easier to clean a git repository is to use 'BFG repo cleaner'
https://rtyley.github.io/bfg-repo-cleaner/
(easier than git-filter-branch and a lot faster!)
But be aware that it will change all the history, modifying sha1 of commits and impacting all the developers!
The two instructions below will go through each commit in your repository and delete the file you've specified in <file>.<extension>
Note: Be careful since this does change the history of your repository!
git filter-branch --tree-filter "rm -f <file>.<extension>" -- --all
or
git filter-branch --index-filter "git rm --cached --ignore-unmatch <file>.<extension>" -- --all
Note: Difference between the two filters (--tree-filter
and --index-filter
) is the place where everything happens. In later, the instruction is carried out in staging area as oppose to working directory. Also, after you run
filter-branch, git
leaves a backup of your tree in the .git directory. By default, you can't run filter-branch again because it won't overwrite the backup. In order to bypass this you can add -f
option after filter-branch
instruction. This will overwrite backup.
cd into your repository and the directory for your files
Example:
cd app/public/images
then enter the following command;
git rm -rf ./*
This will delete the files in your directory from the git repository. To break it down, with git' you're obviously directing git to do something. 'rm' is the command to remove files. the flags '-rf' does two things. The 'r' is to allow recursive removal; and the 'f' is to force action by overriding the up-to-date check.
The './*' selects all the files in the directory you are in when you enter the command.
You can find more info here: https://git-scm.com/docs/git-rm