Make Git consume less disk space?

后端 未结 11 937
鱼传尺愫
鱼传尺愫 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 06:00

    Git clone now has a --single-branch option that allows you to checkout a single branch without pulling in the git history of the other branches. If git is consuming a lot of disk space because you have a lot of branches, you can delete your current checkout and re-clone the repo using this option to regain some disk space. For example:

    cd ../
    rm -rf ./project
    git clone -b master --single-branch git@github.com:username/project.git
    

    Also, if your current master has a long history and you don't have any outstanding branches that need to be merged back into master, you can create an archive branch off of master and create a new orphan master with no git history:

    git checkout -b master_archive_07162013  # create and switch to the archive branch
    git push origin master_archive_07162013  # push the archive branch to the remote and track it
    git branch -D master                     # delete local master
    git push --delete origin master          # delete remote master
    git remote prune origin                  # delete the remote tracking branch
    git checkout --orphan master             # create a new master branch with no history
    git commit -m "initial commit"           # re-establish the files in the repo
    git push origin master                   # push the new master to the remote
    

    The new master branch's tree will not be related to the old archived master branch, so only do this when you are truly archiving the branch.

    If you archive your master branch and then git clone master with single-branch, your checkout should be a lot smaller.

提交回复
热议问题