我如何从git存储库中删除旧的历史记录? [英] How do I remove the old history from a git repository?
问题描述
我有一个拥有大量历史的git仓库:500多个分支,500个+标签,回到2007年年中。它包含约19,500次提交。我们希望在2010年1月1日之前删除所有历史记录,以使其更小并且更容易处理(我们会在归档存储库中保留完整的历史记录副本)。
我知道我希望成为新存储库根目录的提交。然而,我不能找出正确的git mojo来截断回购从那个提交开始。我在猜测一些变体
git filter-branch
$ p涉及移植物的$ p>
将是必要的;可能还需要对待我们要分开保存的200多个分支中的每一个,然后将回购补丁一起回收(我知道该怎么做)。
有没有人做过这样的事情?
解决方案只要创建一个移植过程中你的新根提交给没有父进程(或者提交给一个空的提交,例如你的仓库的真实根提交)。例如。
echo< NEW-ROOT-SHA1> > .git / info / grafts
创建移植后,立即生效;你应该可以看看
git log
,看看不想要的旧提交已经消失:
$ echo 4a46bc886318679d8b15e05aea40b83ff6c3bd47> .git / info / grafts
$ git log --decorate | tail --lines = 11
commit cb3da2d4d8c3378919844b29e815bfd5fdc0210c
作者:Your Name< your.email@example.com>
日期:五月24日14:04:10 2013 +0200
另一个消息
commit 4a46bc886318679d8b15e05aea40b83ff6c3bd47(嫁接)
作者:你的名字< your.email@example.com>
日期:5月23日星期四22:27:48 2013 +0200
某些信息
如果一切看起来都像预期的那样,那么你可以做一个简单的
git filter-branch - --all
来使它永久。
谨慎:在执行 filter-branch 步骤后,所有提交标识符都会发生更改,所以任何使用旧回购不得与任何使用新回购的人合并。
I'm afraid I couldn't find anything quite like this particular scenario.
I have a git repository with a lot of history: 500+ branches, 500+ tags, going back to mid-2007. It contains ~19,500 commits. We'd like to remove all of the history before Jan 1, 2010, to make it smaller and easier to deal with (we would keep a complete copy of the history in an archive repository).
I know the commit that I want to have become the root of the new repository. I can't, however, figure out the correct git mojo to truncate the repo to start with that commit. I'm guessing some variant of
git filter-branch
involving grafts would be necessary; it might also be necessary to treat each of the 200+ branches we want to keep separately and then patch the repo back together (something I do know how to do).
Has anyone ever done something like this? I've got git 1.7.2.3 if that matters.
解决方案Just create a graft of the parent of your new root commit to no parent (or to an empty commit, e.g. the real root commit of your repository). E.g.
echo "<NEW-ROOT-SHA1>" > .git/info/grafts
After creating the graft, it takes effect right away; you should be able to look at
git log
and see that the unwanted old commits have gone away:$ echo 4a46bc886318679d8b15e05aea40b83ff6c3bd47 > .git/info/grafts $ git log --decorate | tail --lines=11 commit cb3da2d4d8c3378919844b29e815bfd5fdc0210c Author: Your Name <your.email@example.com> Date: Fri May 24 14:04:10 2013 +0200 Another message commit 4a46bc886318679d8b15e05aea40b83ff6c3bd47 (grafted) Author: Your Name <your.email@example.com> Date: Thu May 23 22:27:48 2013 +0200 Some message
If all looks as intended, you can just do a simple
git filter-branch -- --all
to make it permanent.BEWARE: after doing the filter-branch step, all commit ids will have changed, so anybody using the old repo must never merge with anyone using the new repo.
这篇关于我如何从git存储库中删除旧的历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!