Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git large pack file, delete and rewrite?

Tags:

git

I have a relatively small git repository containing a standard Wordpress installation. However, I accidentally added a "concept" folder in the repository which contains many large psd files.

The problem is that now, after 50 commits, git has created a "pack" file, which is 1,3 GB.

To downsize the pack folder I tried to remove my "concept" folder via:

git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch DIRECTORY/' --prune-empty --tag-name-filter cat -- --all

and afterwards

git gc --aggressive --prune

After the execution of these commands, my "concept" folder was deleted from the file system and from all commits but the pack file is still exactly 1,3 GB

Is there anything else I can do to reduce the size of the pack folder?

like image 457
agrT Avatar asked Jul 11 '14 08:07

agrT


People also ask

How do I delete large files in git?

If the large file was added in the most recent commit, you can just run: git rm --cached <filename> to remove the large file, then. git commit --amend -C HEAD to edit the commit.

How do I delete large binary files in git?

You can do this by getting your local repository in order using the git rebase command, then using the git push --force command to overwrite the server repository with your local repository.

Can I just delete the .GIT file?

If you're familiar with the terminal window or the DOS prompt, you can easily perform a command line Git repository delete. 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.


1 Answers

I mentioned before that a git gc alone can actually increase the size of the repo).

The commands I was listing were:

# remove the temporary history git-filter-branch otherwise leaves behind for a long time
rm -rf .git/refs/original/ && git reflog expire --all &&  git gc --aggressive --prune=now

If that doesn't work, check out the BFG tool.

You will find an even more complete gc in "How to remove unreferenced blobs from my git repo"

This article suggests a similar approach:

rm -rf .git/refs/original/
git reflog expire --expire=now --all
git fsck --full --unreachable
git repack -A -d
git gc --aggressive --prune=now
like image 179
VonC Avatar answered Oct 10 '22 05:10

VonC