Make Git consume less disk space?

后端 未结 11 939
鱼传尺愫
鱼传尺愫 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:03

    You might have a lot of git projects cloned on your computer, but only a few of them you are actively working on today.

    In those idle projects, the checked out working files can consume a significant amount of disk space. (Sometimes even larger than git's history, because history gets compressed.)

    • So one way to save disk space is to remove the working files from idle projects you are not working on. A nice way to do that is to create an empty branch which you can switch to when you are not working on the project.

    • Another more drastic thing you can do is to delete absolutely everything except for the .git/config file. Or just remove the largest folder, the git history:

      rm -rf .git/objects
      

      That will allow you to git fetch again in future, when you want the history and the files back. Before doing this, you should ensure that you have pushed all your work (including local branches) to the remote repository, so there is nothing in the local git repo that you need to retain.

提交回复
热议问题