过非交互式地压缩除最近的提交之外的所有提交来减少臃肿的Git仓库

过非交互式地压缩除最近的提交之外的所有提交来减少臃肿的Git仓库

本文介绍了如何通过非交互式地压缩除最近的提交之外的所有提交来减少臃肿的Git仓库的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Git repo拥有数百GB的数据,所以我试图删除陈旧过时的提交,因为它们让一切变得更大更慢。我需要一个快速的解决方案;越快越好。



如何压缩除最近
之外的所有提交,并且不必手动压缩每个提交一个在?具体来说,我不想使用

  git rebase -i --root 



我的回购



我有这些提交:

  A .. B .. C ... ... H .. I .. J .. K .. L 


我想要的是(压缩 A 和<$ c之间的所有内容

 <$ c $> >  c> A .. H .. I .. J .. K .. L 

回答如何,但我想保留一些
更新的提交。我不想 。 (特别是我需要保持前两个提交从顶端计数)。

解决方案

最快计数实施时间几乎肯定会与移植物和顺序工作输出。



重建是为了对不同内容应用更改而设计的。你在这里做的是保存内容并故意丢失产生它们的变化历史,所以几乎所有的rebase最繁琐和缓慢的工作都被浪费了。

有效载荷这里是,根据你的图片工作,

  echo`git rev-parse H; git rev-parse A`> .git / info / grafts 
git filter-branch - --all


过滤分支非常小心在任何一点出现故障后都可以恢复,这当然是最安全的......但只有在事情向南发展时,通过简单重做恢复才不会更快更容易。失败并不常见,重新启动通常很便宜,但要做的就是做一个安全但非常快速的操作,这些操作几乎都可以工作。为此,这里最好的选择是在tmpfs上执行它(我知道在Windows上最接近的是一个ramdisk,像的 - 共享选项,请检查克隆的内部以查看实际效果,这非常简单。

#切换到tmpfs上的轻量级wip克隆
git clone --shared - 不结账。 / t / wip / filterwork
cd!

#移除不需要的提交
echo`git rev-parse $ L; git rev-parse $ A`> .git / info / grafts
git filter-branch - --all

检查回购历史记录是否正确
git log --graph --decorate --oneline --all

#全部完成拼接,filter-branch已经集成了
rm .git / info / grafts

#将重写的历史推回
git push origin --all --force

对于您可能想要做的事情以及您的回购计划中可能存在的差异,几乎所有这些命令的选项都可能有用。以上内容已经过测试,并会按照它所说的做,但这可能不是您想要的。


My Git repo has hundreds of gigabytes of data, so I'm trying to remove old, outdated commits, because they're making everything larger and slower. I need a solution that's fast; the faster, the better.

How do I squash all commits except for the most recentones, and do so without having to manually squash each one in an interactive rebase? Specifically, I don't want to have to use

git rebase -i --root

My repo

I have these commits:

A .. B .. C ... ... H .. I .. J .. K .. L

What I want is this (squashing everything in between A and H into A):

A .. H .. I .. J .. K .. L

There is an answer on how to squash all commits, but I want to keep some of themore recent commits. I don't want to squash the most recent commits either. (Especially I need to keep the first two commits counting from the top.)

解决方案

Fastest counting implementation time is almost certainly going to be with grafts and a filter-branch, though you might be able to get faster execution with a handrolled commit-tree sequence working off rev-list output.

Rebase is built to apply changes on different content. What you're doing here is preserving contents and intentionally losing the change history that produced them, so pretty much all of rebase's most tedious and slow work is wasted.

The payload here is, working from your picture,

echo `git rev-parse H; git rev-parse A` > .git/info/grafts
git filter-branch -- --all

Filter-branch is very careful to be recoverable after a failure at any point, which is certainly safest .... but it's only really helpful when recovery by simply redoing it wouldn't be faster and easier if things go south on you. Failures being rare and restarts usually being cheap, the thing to do is to do an un"safe" but very fast operation that is all but certain to work. For that, the best option here is to do it on a tmpfs (the closest equivalent I know on Windows would be a ramdisk like ImDisk), which will be blazing fast and won't touch your main repo until you're sure you've got the results you want.

So on Windows, say T:\wip is on a ramdisk, and note that the clone here copies nothing. As well as reading the docs on git clone's --shared option, do examine the clone's innards to see the real effect, it's very straightforward.

# switch to a lightweight wip clone on a tmpfs
git clone --shared --no-checkout . /t/wip/filterwork
cd !$

# graft out the unwanted commits
echo `git rev-parse $L; git rev-parse $A` >.git/info/grafts
git filter-branch -- --all

# check that the repo history looks right
git log --graph --decorate --oneline --all

# all done with the splicing, filter-branch has integrated it
rm .git/info/grafts

# push the rewritten histories back
git push origin --all --force

There are enough possible variations on what you might be wanting to do and what might be in your repo that almost any of the options on these commands might be useful. The above is tested and will do what it says it does, but that might not be exactly what you want.

这篇关于如何通过非交互式地压缩除最近的提交之外的所有提交来减少臃肿的Git仓库的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 19:50