How to reduce disk space usage in a large reposito

2020-03-06 16:49发布

问题:

I have a git repository with about 1 year of development history, and it is already 37GB. How can I minimize the size in a way where I will delete the old history? That is, I only need the history that covers the last 2 months, others can be removed.

回答1:

The three main options are:

  • removing large files from the history (with, for instance, BFG)
  • split a repo subfolder into its own repo
  • split a repo history (starting with a new repo from HEAD of new repo, keeping the old one for archive).

On the last point, see "How do I remove the old history from a git repository?", using a script like this one (with the SHA1 of the commit from 2 months ago, as a parameter)

#!/bin/bash
git checkout --orphan temp $1
git commit -m "Truncated history"
git rebase --onto temp $1 master
git branch -D temp

# The following 2 commands are optional - they keep your git repo in good shape.
git prune --progress # delete all the objects w/o references
git gc --aggressive # aggressively collect garbage; may take a lot of time on large repos

Since it rewrites the history, you will need a git push --force.
Since the OP is pushing to git.assembla.com (see discussion), this issue clearly states

You need to enable the --force option.
This is done from the Git repository Settings tab. You need to be an 'Owner' on the space to see the settings tab.



标签: git disk