Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Shrink/Cut a Git Repo

Tags:

git

branch

We have a Git repo with 7 contributing developers with over 2.5 years of history and about 10,000 commits. We use Assembla to push and pull from. When we add new developers cloning the repo to their dev computers takes almost an hour.

I'm not sure if this is the proper terminology, but our goal is to "shrink" the repo by "cutting/snipping" off the first 1.5 years worth of commits and keeping only the latest year of history. We want to keep a "backup" copy of the entire repo, whether as a separate repo or maybe a branch? We'd like to repeat this in the future an possible merge the initial split with the new split when needed, but I'm not sure if this is possible. If there is a way to have all the history on a separate branch and just keep the master branch with only the history for the last year, that would be great, but let me know of possible pros and cons.

I don't know of all the possibilities/options we have which is why I am here. I read something about patches but I'm not sure if that truly is what I need or if there is something better/easier. What are you guys doing to take care of an issue like this, including pros and cons? Keep in mind, I still need every developer to continue to push and pull, preferably staying on the master branch.

Thanks in advance!

like image 736
RoLYroLLs Avatar asked Nov 21 '13 16:11

RoLYroLLs


1 Answers

The best step-by-step instructions can be found on the Git SCM historical blog post "Replace Kicker" or in the Git book's chapter on "Replace".

The short summary is this:

  • Create a new branch that is at the point where you want to cut, say git branch history hash.
  • Push the history to a new repository.
  • Create a new base using git commit-tree.
  • Rebase your post-history commits onto your new base.
  • Push your new truncated master branch up to the server.
  • People can then use git replace to re-connect the history together.

The original post explains it much better with pictures.

When dealing with complex histories involving merges, this may not work well, depending on how well git rebase --onto works with --preserve-merges. You should obviously test well before proceeding.

like image 99
Emil Sit Avatar answered Oct 24 '22 23:10

Emil Sit