简体   繁体   中英

Reduce Repo Size on Bitbucket

I've realised my repo is coming in at just over 1GB, it seems my .git folder weighs in at 800MB. Why is this and what are the right ways to go about reducing this?

Any help is appreciated. Thanks in advance!

Your .git folder is bloated somehow, most likely due to git history or old assets:

Source: http://blogs.atlassian.com/2014/05/handle-big-repositories-git/

  • They accumulate a very very long history (the project grows over a very long period of time and the baggage accumulates).
  • They include huge binary assets that need to be tracked and paired together with code.
  • Both of the above.

Here are some ways to remedy it:

Shadow Clone Method

Run git clone --depth <# of commits of history> <remote-url> .

Filter-branch Method for large binary files or old assets like old PSDs

Run something like git filter-branch --tree-filter 'rm -rf /path/to/spurious/asset/folder' HEAD . Beware filter-branch can rewrite the history of your commits, thus others who have an older version of your repository will need to clone it again. Warn your coworkers before you do this method!

There are more methods and alternative ways in the atlassian link above.

EDIT: Make sure to create a backup repo of your original repo just in case!

Instead of using git filter-branch manually, I highly recommend using the BFG ( https://rtyley.github.io/bfg-repo-cleaner/ ), since it is much faster and can help you get rid of larger files. The instructions on that page are very easy to follow.

However, note that the BFG removes large files from your .git history only if they are NOT currently committed to your repo. Before you use the BFG, you should

git rm --cached FILENAME

any large files (like large zips as you mentioned above). If you don't need them anymore, you can just delete them completely. And remember to add *.zip to your .gitignore!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM