0

I have a repository with over 35.000 commits at master. It's huge at storage (over 14 GB), and I want to remove all older commits than 6 months and keep all the changes. I mean, I dont need f.ex. 30.000 history commits, I just want to keep last 5.000. Do you have any solution to make it happen?

I was wondering about creating new repository from existing with HEAD^5000, then try to pull the rest, but I dont know if it will work. Also was thinking about editing .git directory, but it may be not easy at all.

It might work with rebase/squash, but can I do it historical and I wont have conflicts when I will pull master to develop/feature, or any current merge requests?

Karol Gasienica
  • 2,825
  • 24
  • 36
  • What’s the point of using source control utility like Git if you’re just going to consolidate commits…? – Martin Bean Jul 06 '20 at 11:00
  • I don't think you can do that without any conflicts, because now the 5,000th-ago commit will have changed its parent (from the 5,001st to having no parent) which makes it a different commit, which means the 4,999th is now a different commit with a different parent and so on. If the problem is slow cloning, look into doing so *shallowly*. – jonrsharpe Jul 06 '20 at 11:00
  • @MartinBean we need to share our GIT and it's history for last 6 months to our contractor. We can't do it with whole repository with all our commits. – Karol Gasienica Jul 06 '20 at 11:01
  • 2
    Does this answer your question? [How do I remove the old history from a git repository?](https://stackoverflow.com/questions/4515580/how-do-i-remove-the-old-history-from-a-git-repository) – Joe Jul 06 '20 at 11:01
  • @Joe thanks! I will check it :) – Karol Gasienica Jul 06 '20 at 11:03

1 Answers1

0

you can re-write a repo history with something like git-filter-repo; BTW it has some cooler ways to reduce repo size such as removing obsolete large blobs, maybe try the --analyze flag first.

please note that re-writing a shared git history will require all collaborators to port their local changes onto the new history which could be quite time consuming to say the least. you should probably coordinate the migration to the new history with them too.

Nitsan Avni
  • 753
  • 6
  • 6