gpt4 book ai didi

git - 如何从 git 存储库中删除旧的历史记录?

转载 作者:IT王子 更新时间:2023-10-29 01:16:25 25 4
gpt4 key购买 nike

恐怕我找不到与此特定场景非常相似的内容。

我有一个包含大量历史的 git 存储库:500 多个分支、500 多个标签,可以追溯到 2007 年年中。它包含约 19,500 个提交。我们想删除 2010 年 1 月 1 日之前的所有历史记录,以使其更小且更易于处理(我们将在存档存储库中保留历史记录的完整副本)。

我知道我想要成为新存储库根目录的提交。但是,我无法找出正确的 git mojo 来截断 repo 以从该提交开始。我猜是

的一些变体
git filter-branch

涉及移植物是必要的;可能还需要分别处理我们想要单独保留的 200 多个分支,然后将 repo 修补回一起(我知道该怎么做)。

有没有人做过这样的事情?如果重要的话,我有 git 1.7.2.3。

最佳答案

也许现在发布回复为时已晚,但由于此页面是 Google 的第一个结果,它可能仍然有用。

如果你想在你的 git 仓库中释放一些空间,但不想重建你所有的提交( rebase 或移植),并且仍然能够从拥有完整仓库的人那里推送/pull/merge ,你可以使用 git clone 克隆(--depth 参数)。

; Clone the original repo into limitedRepo
git clone file:///path_to/originalRepo limitedRepo --depth=10

; Remove the original repo, to free up some space
rm -rf originalRepo
cd limitedRepo
git remote rm origin

您可以按照以下步骤浅化现有的存储库:

; Shallow to last 5 commits
git rev-parse HEAD~5 > .git/shallow

; Manually remove all other branches, tags and remotes that refers to old commits

; Prune unreachable objects
git fsck --unreachable ; Will show you the list of what will be deleted
git gc --prune=now ; Will actually delete your data

How to remove all git local tags?

Ps: 旧版本的 git 不支持克隆/推送/pull 出浅层存储库。

关于git - 如何从 git 存储库中删除旧的历史记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4515580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com