git - 截断 GIT 历史(有 2 个永久分支)

标签 git version-control tortoisegit

自 2013 年 8 月 13 日以来,我们有一个 git 存储库,提交了 4000 多次,占用了将近 7 GB 的磁盘空间。 (GIT版本:2.9.0.windows.1)

在这些年里,项目发生了很大变化,因此最旧的提交已不再有用。

与其他许多人一样,我们希望“巩固”某个特定日期的历史记录。 假设我们想要将超过 6 个月的任何内容“压缩”在一起,成为一个单一的大提交。

主要的障碍是我们有一个多分支结构,显然我们想保留它:

  • 主分支(永久)
  • 开发分支(永久)
  • 特征分支(每个任务一个, merge 后删除)

例如, 这就是历史现在的样子:

How the history looks now

这是我们需要的:

What we need

我们尝试了几种方法,例如“Rebase”、“Cherry pick”、“深度”的“克隆”……但似乎没有任何方法能够满足我们的需求。 这些是我尝试过的最有意义的事情:

  • Rebase 和 Cherry pick(使用 tortoiseGit 2.1.0.0) 使用这两个命令,我都试图“压缩”最旧的提交,但每次 merge 都会导致对话“你想选择哪个父级?parent1/parent2”,然后无论我选择哪个:所有文件都被标记为“冲突”并且所以他们需要“手动”解决。 我无法手动处理所有这些冲突(也无法为 Master 和 Develop 分支重现相同的序列)。

  • 深度克隆(通过 Git-Bash) 我执行了这个命令: “git clone limitedRepo --depth=1000”正确地“压缩”了所有旧的提交,但生成的 repo 只有一个分支。

所以我尝试了这个命令从原点取回 Develop 分支:

“git remote set-branches origin '*'” “git fetch -vvv”

但获取的分支包含整个历史,而不是我们需要的“压缩”。

我尝试使用具有不同参数的相同命令,但我只是在摸索。

有什么想法吗?

最佳答案

也许这不是占用磁盘空间的提交数量,而是可能是您的存储库历史记录中存在的大文件的多个版本,但此后已从您的代码的当前版本中删除。 Pro Git有一个名为 Removing Objects 的部分这允许您从 Git 历史记录中删除大文件。

There are a lot of great things about Git, but one feature that can cause issues is the fact that a git clone downloads the entire history of the project, including every version of every file. This is fine if the whole thing is source code, because Git is highly optimized to compress that data efficiently. However, if someone at any point in the history of your project added a single huge file, every clone for all time will be forced to download that large file, even if it was removed from the project in the very next commit. Because it’s reachable from the history, it will always be there.

(强调,我的)

... Be warned: this technique is destructive to your commit history. It rewrites every commit object since the earliest tree you have to modify to remove a large file reference. If you do this immediately after an import, before anyone has started to base work on the commit, you’re fine – otherwise, you have to notify all contributors that they must rebase their work onto your new commits.

现在您需要做的就是find large files in your repository history .

相关 StackOverflow 帖子:Remove old commit information from a git repository to save space

无论您如何做,一个团队范围的 git rebase 都在您的 future 。

关于git - 截断 GIT 历史(有 2 个永久分支),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39123289/

相关文章:

python-3.x - pip 安装私有(private) Github 存储库的简单方法?

git - 如何从 tmux.conf 导出函数

git - 从所有以前的提交中删除一个目录

c# - 为什么应该将 NuGet 包 dll 添加到源代码管理中?

git - 如何使用 TortoiseGit 在本地 checkout fork 的 pull 请求?

git - git 在什么时候完成它的执行操作?

git - 我可以在 GitHub 上托管我的 Office 加载项吗?

git - 修复已推送的 'backwards' git merge

tortoisegit - TotalCommander 的自定义快捷方式并在当前文件夹中调用 TortoiseGit 日志

git - 如何使用 git-extensions 获取图标覆盖