Is there a way to reduce the size of the git folder?

后端 未结 7 1744
眼角桃花
眼角桃花 2020-12-12 09:44

Seems like my project is getting bigger and bigger with every git commit/push. Is there a way to clean up my git folder?

相关标签:
7条回答
  • 2020-12-12 09:57

    yes yes, git gc is the solution, naturally,

    and locally - you can just delete the local repository and clone it again,

    but there is something more important here...

    the seconds you wait for that huge git & externals to process are collected to long minutes in which are collected to hours of inefficient time spent,

    Create a new (entirely, not just a branch) repository from scratch, including the only recent version of files, naturally you'll loose all the history,

    but when in code-world it is not time to get sentimental, there is no point dragging along the entire 5 years of code every commit or diff, you can still store the old git & externals somewhere, if you get nostalgic :]

    but, at some point you really have to move along :]

    your team will thank you!

    0 讨论(0)
  • 2020-12-12 09:57

    Running this command is extremely dangerous, but will shrink your repository by erasing all your git recovery/backup files:

    git reflog expire --expire=now --all && git gc --prune=now --aggressive
    

    It will erase all files git uses to recover your repository from some bad command, for example, if you did git reset --hard, you can usually recover the files lost. But if you do git reset --hard before the git reflog expire... command, then you lost everything. Now, your only hope is to use some tool which analyses your file system and try to recover the erased files, if they were not overridden.

    0 讨论(0)
  • 2020-12-12 10:05

    Don't know if it will shrink it, but after I run git clean, I often do git repack -ad as well, which reduces the number of pack files.

    0 讨论(0)
  • 2020-12-12 10:08

    Run:

    git remote prune origin
    

    Deletes all stale tracking branches which have already been removed at origin but are still locally available in remotes/origin.

    git gc --auto
    

    'G arbage C ollection' - runs housekeeping tasks (compresses revisions, removes loose/inaccessible objects). The --auto flag first determines whether any work is required, and exits without doing anything if not.

    0 讨论(0)
  • 2020-12-12 10:12

    I'm not sure what you want. First of all, of course each time you commit/push the directory is going to get a little larger, since it has to store each of those additional commits.

    However, probably you want git gc which will "cleanup unnecessary files and optimize the local repository" (manual page).

    Another possibly relevant command is git clean which will delete untracked files from your tree (manual page).

    0 讨论(0)
  • 2020-12-12 10:14

    git clean -d -f -i is the best way to do it.

    This will help to clean in a more controlled manner.

    -i stands for interactive.

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