简体   繁体   中英

How can I reduce the size of .git folder with huge history of commits?

We are working in a group and commiting data daily in large numbers due to which .git folder is becoming very heavy in size. And while performing the pull command on our system, it takes a lot of time due to heavy size of .git folder. How can we clean or reduce the size of this git repo ?

You need to determine if there is something inherently big in your repository --like too many big binary files-- or if a garbage collection will fix it.

Do a garbage collection, see how big your repo is.

If that doesn't fix it, look at the Atlassian link that @sauerburger provided, or do some other googling based on what you find there.

(The details of these steps are intentionally left as an exercise for the user.)

If most of the file size is taken up by old commits in the .git folder, rather than current files, what you can do is rebase a specific recent commit as the root, keeping all files and commits from that point on but getting rid of older history.

Make sure to back everything up first!

Quoting this answer ( https://stackoverflow.com/a/24153726/7070218 ):

One way to do this is here, assuming your current work is called branchname . I like to use a temp tag whenever I do a large rebase to double-check that there were no changes and to mark a point I can reset back to if something goes wrong (not sure if this is standard procedure or not but it works for me):

 git tag temp git checkout 10004 git checkout --orphan new_root git commit -m "set new root 10004" git rebase --onto new_root 10004 branchname git diff temp # verification that it worked with no changes git tag -d temp git branch -D new_root 

To get rid of the old branch you'll need to delete all tags and branch tags on it; then

 git prune git gc 

will clean it from your repo.

Note that you'll temporarily have two copies of everything, until you have gc 'd, but that is unavoidable; even if you do a standard squash and rebase you still have two copies of everything until the rebase finishes.

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