如何收缩/剪切Git Repo [英] How to Shrink/Cut a Git Repo

查看:361
本文介绍了如何收缩/剪切Git Repo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有7个贡献开发人员的Git回购协议,拥有超过2.5年的历史和约10,000次提交。我们使用Assembla来推拉。当我们添加新的开发人员时,将repo克隆到他们的开发计算机需要近一个小时。



我不确定这是否是适当的术语,但我们的目标是通过切断/剪切掉第一个1.5年的承诺并保留最近的历史年份来回购回购。我们希望保留整个回购的备份副本,无论是作为单独的回购还是分支?我们希望在未来再次重申这一点,在需要时可能会将初始分割与新分割合并,但我不确定这是否可行。如果有一种方法可以将所有历史记录保存在一个单独的分支上,并且仅保留 master 分支仅包含去年的历史记录,那就太好了,但让我了解可能的优点和缺点。

我不知道我们拥有的所有可能性/选项,这就是我来到这里的原因。我读了一些关于 patch的文章,但我不确定这是否真的是我需要的,或者是否有更好的/更容易的东西。你们正在做什么来照顾这样的问题,包括利弊?请记住,我仍然需要每个开发人员继续推拉,最好留在 master 分支中。



提前致谢!

解决方案

最好的分步说明可以在Git SCM博客文章替换踢球者



简短的总结是这样的:




  • 创建一个新的分支,它位于要切割的位置,比如 git分支历史记录 hash

  • 将历史记录推送到新的存储库。新的基础使用 git commit-tree

  • 重新发布您的信息 - history 提交到您的新基地。

  • 将新截断的 master 分支推送到服务器。

  • 然后,人们可以使用 git replace 重新连接历史记录。


<原来的文章解释了很多



在处理涉及合并的复杂历史时,这可能无法正常工作,具体取决于 git rebase --onto code>使用 - preserve-merges 。在继续操作之前,您应该明显地测试。


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!

解决方案

The best step-by-step instructions can be found on the Git SCM blog post "Replace Kicker".

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.

这篇关于如何收缩/剪切Git Repo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆