![]() ![]() Squashing history to reduce repository size That's our "project-history" repository complete. While the remote repository contains only the commits up to and including "Add support for EF Core global conventions" ( 590f4d3): # Push the history branch to the remote repository git push project-history history:mainĪfter pushing to the remote repository, our original clone looks something like this: # Add the remote repository to original clone git remote add project-history C: \repos \git-replace \history Instead, for simplicity, I'm going to push to a local folder for now, and treat that as a remote # Initialize the "remote" repository git init C: \repos \git-replace \history In practice you'd create a new git repository on GitHub (for example) and push to that. Now we can create our "project-history" repository by pushing this branch to a new remote git repository. First, we would create a new branch called history at this commit: git branch history 590f4d3 Lets say, we want to "archive" the history from the "Add support for EF Core global conventions" commit ( 590f4d3). Visually, these commits are linearly ordered with each pointing to the parent commit: Obviously it goes on beyond that, but that's sufficient for now. 0a698f1 (HEAD - > main, tag: v1.0.0-beta06, origin/main, origin/HEAD ) Bump version to beta06Ġa1a180 Add "#pragma warning disable 1591" to generated codeĥ90f4d3 Add support for EF Core global conversionsĥ242f13 Add support for NewId package ( #52)ĩde5ea0 (tag: v1.0.0-beta05 ) Merge pull request #42 from andrewlock/single-package-attempt-2 We'll start by cloning the original repository into a folder: git clone įrom the command line, this looks like the following ( git log -oneline). This post is based on the Git Tools - Replace entry from the git book - it's pretty much the same thing, I've just worked through it to make sure I understand! You also need to be aware that this requires some rewriting (rebasing) of commits, so be careful! The ability to merge them together when required, grafting the history onto our "current" repository!įor convenience, I'm going to demonstrate the general approach using one of my smaller repositories, StronglyTypedId, but you would really only want to do this with repositories that have become too large and unwieldly.A "history" repository containing all the commits prior to the creation of the new repository.A small "current" repository containing a minimal amount of history.For the rest of the post I'll explore how we can achieve the best of both worlds: However, I found out recently that we could have had our cake and eaten it by using git replace. We decided against it in the end, as the benefits just weren't good enough to justify the inconvenience when you do need the history. Con If you need information from both the new and old repository, that's hard to work with.Con git blame becomes less useful, as you can't see any history prior to the first commit. ![]() Pro You can still see the project history prior to the change in the old repository.NET runtime repo as an example, it would go from 631MiB to ~90MiB Pro git clone becomes much faster as the repository is much smaller without the history.We contemplated starting "fresh" by creating a new git repo, copying all the files across, and archiving the old repository. Recent commits carry a lot of value, and the older the commits, the lower the value. ![]() I don't generally deal with repos that big, but I have had to work on some sizeable repositories, and the sad truth is that most of the time, you really don't need that history from 5 years ago. That history is a large part of where git gets its power, so you don't generally want to lose it, but there are times when it makes sense. ![]() Most of that size is taken up by the history of 117,251 commits, as opposed to the sheer number of files. Updating files: 100% ( 59281/59281 ), done.ĭoing a fresh clone, you need to download 1.9 million objects, equating to 631MiB. Remote: Compressing objects: 100% ( 41/41 ), done. Remote: Counting objects: 100% ( 44/44 ), done. Remote: Enumerating objects: 1933225, done. That's not surprising when you see the size of it: > git clone NET runtime git repository? If you have you should know it takes a looooong time to clone. Background: when repositories get too big This is made possible by the git-replace tool. In this post I look at how you can split a repository in two, creating a "history" repository, and a current repository, while retaining the ability to temporarily merge them again when required. ![]()
0 Comments
Leave a Reply. |