Git-filter-repo:一个强大的 Git 仓库过滤器
Git-filter-repo
Git-filter-repo 是一个高度可定制的 Git 仓库过滤器,可以用来重写仓库历史记录,仅仅保留指定的文件或目录,或者将仓库拆分成多个不同的仓库。
安装
您可以使用 pip 安装它:
pip install git-filter-repo
或者您可以从 GitHub 克隆源代码并安装:
git clone https://github.com/newren/git-filter-repo.git
cd git-filter-repo
sudo python3 setup.py install
使用
使用 Git-filter-repo 最简单的方法是通过以下命令:
git filter-repo
这将过滤当前目录中的 Git 仓库。有关更多详细信息,请参见 选项。
示例
以下示例演示了如何使用 Git-filter-repo。假设我们有一个仓库,其中包含很多大文件,我们想要只保留最近的 10 个提交,并将所有大文件删除。
首先,我们将使用以下命令生成一个新的分支:
git branch big-file-removal
接下来,我们将切换到新分支:
git checkout big-file-removal
现在,我们可以使用 Git-filter-repo 将我们的仓库重写为只包含最近的 10 个提交:
git filter-repo --commit-filter '
if commit_number < 10:
yield commit
' --force
最后,我们可以使用以下命令将大文件从仓库中删除:
git filter-repo --invert-paths --path-glob '*_big_file*' --force
现在我们的仓库已被重写,只保留了最近的 10 个提交,并且已删除了所有大文件。
原文地址: https://www.cveoy.top/t/topic/lPng 著作权归作者所有。请勿转载和采集!