How to compress / cut Git Repo

We have a Git repository with 7 developer contributors with more than 2.5 years of history and about 10,000 commits. We use Assembla to push and pull. When we add new repo cloning developers, their development computers take almost an hour.

I’m not sure that this is the correct terminology, but our goal is to “squeeze” the repo by “cutting off / separating” from the first minutes of fixing and saving only the last year of history. We want to keep a "backup" of the entire repo, whether it is a separate repo or, possibly, a branch? We would like to repeat this in the future, perhaps merging the initial split with a new split when necessary, but I'm not sure if this is possible. If there is a way to have the whole story 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 about the possible pros and cons.

I do not know all the options / options that we have, so I am here. I read something about patches , but I'm not sure if this is really what I need, or if something is better / easier. What are you guys doing to take care of such a problem, including the pros and cons? Keep in mind, I still need every developer to keep pushing and pulling, preferably staying on the master branch.

Thanks in advance!

+6
source share
2 answers

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

A brief summary is as follows:

  • Create a new branch at the point where you want to cut, say, git branch history hash.
  • Move the story to a new repository.
  • Create a new database using git commit-tree .
  • Relocate your post- history commits to the new database.
  • Move the new truncated master branch to the server.
  • People can then use git replace to reconnect the story.

The original post explains this much better with photos.

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

+7
source

Disclaimer: You must first run a test repo, as the commands given here may destroy your data .

You can edit (i.e. edit a script) history through a quick export mechanism. The first step is to run git fast-export --signed-tags=strip --no-data --full-tree --export-marks=export.marks branch1 branch2 [...] branchN > commits.fi . Now you have a quick import of all your branches. In this thread, you can remove the commit by deleting the lines from commit refs / ... to the final new line. You also need to remove the lines from :<mark> line (as well as merge :<mark> if your new story begins with a merge) from your new "first" commit.

To help this process, you should study the revision graph and accept the changes when no merges cross their history. In the following graph, A, D, and F are good candidates to start. B or C have a problem that the successor of D also depends on G and A.

 A ---- B ---- C ---- D --- E ---- F \ / \ \ / \--- G ------- H \--I--J-/ 

Using the export.marks file export.marks you can translate the commit identifier to mark numbers in the stream.

You need to give your branches new names, since git fast-import will not accept the new history, because new branches do not contain commits from existing ones.

After creating a new story, you need to import it using git fastimport < manipulated-history.fi into an existing repo.

Now it's time to check if the import is correct. To do this, you need to clone the repo into a temporary one, and in this temporary repo you create a graft for each newly created commit so that it has the same parent revisions as before. After that, you run git filter-branch newBranch1 newBranch2 [...] newBranchN . The import was correct if each newBranch now remains with the same message as the corresponding branch.

When everything works so far, you can create a new repo and pull the newBranch branches from the first working clone into it and make it a new working repo. Also note that you should not leave any transplant repositories anywhere, since transplants can be harmful .

0
source

Source: https://habr.com/ru/post/958579/


All Articles