Make Git consume less disk space?

后端 未结 11 874
鱼传尺愫
鱼传尺愫 2020-12-24 05:19

What is the best way for git to consume less disk space?

I\'m using git-gc on my repositories (which does help, especially if there have been many commits since it w

相关标签:
11条回答
  • 2020-12-24 05:36

    Depending on what you want to do with your repository, you might also consider using the following git clone option:

       --depth <depth>
           Create a shallow clone with a history truncated to the specified
           number of revisions. A shallow repository has a number of
           limitations (you cannot clone or fetch from it, nor push from nor
           into it), but is adequate if you are only interested in the recent
           history of a large project with a long history, and would want to
           send in fixes as patches.
    
    0 讨论(0)
  • 2020-12-24 05:45

    Git gc will remove unused objects. That is about everything you can do.

    You could consider splitting up your repositories if they become too big.

    0 讨论(0)
  • 2020-12-24 05:46

    There are a few suggestions I can offer:

    1. Delete no longer used branches. They can pin some commits that you don't use and would never use. Take care however to not delete branches that you would later need (perhaps for review, or for comparison of failed effort). Backup first.

    2. Check if you didn't commit some large binary file (perhaps some generated file) by mistake. If you have, you can purge it from history using "git filter-branch"... well, if you didn't share the repository, or it is worth aggravating other contributors to rewrite history. Again: backup first.

    3. You can prune more aggressively, discarding some safeties, bu using git gc --prune=now, or low-level git prune. But take care that you don't remove safeties and backups (like reflog) that you need minute after compacting.

    4. Perhaps what enlarges your repository are some untracked files in working directory. There "make clean" or "git clean" might help (but take care that you don't remove some important files).

    5. Most safe of all those suggestions: you can try to pack more aggressively, using --depth and --window option of low-level git-repack. See also Git Repack Parameters blog post by Pieter de Bie on his DVCS Comparison blog, from June 6, 2008. Or "git gc --aggressive".

    0 讨论(0)
  • 2020-12-24 05:51

    You can repack your repository. However i think it's called by git gc

    git repack -ad

    0 讨论(0)
  • 2020-12-24 05:56

    git-gc calls lots of other commands that are used to clean up and compress the repository. All you could do is delete some old unused branches.

    Short answer: No :-(

    0 讨论(0)
  • 2020-12-24 05:56

    If you do not need to keep all of the commit history locally, you could use a shallow clone:

    git clone --depth=1 [url_of_repo]
    

    I frequently use this when cloning github projects, if I am only interested in the latest set of files and not in the history.

    Apparently fetching and pushing is/was not support on shallow clones, but I have been able to successfully push and pull changes to github repos with it, so it might work in your case too. (But no doubt you will run into difficulties if you want to merge branches but don't have the base commit in history.)

    I think it is easier to start with a fresh clone as shown above, but others have shown how to trim an existing local repo.

    0 讨论(0)
提交回复
热议问题