window环境使用git-filter-repo

本地环境git >= 2.36.0 python3 >= 3.6

1. 找到你下载的文件

你从 GitHub 下载解压后,里面有一个 没有后缀的文件

复制代码
git-filter-repo

把它复制出来。

2. 粘贴到 你要清理的项目根目录

比如你的项目是:

复制代码
D:\my-project\

就把 git-filter-repo 粘贴到这里:

复制代码
D:\my-project\git-filter-repo

3. 打开 Git Bash,进入项目目录

复制代码
cd D:/my-project

二、Windows 上直接使用的命令(复制就能跑)

最常用:清理 Git 历史里的超大文件(瘦身 .git)

复制代码
python git-filter-repo --strip-blobs-bigger-than 1M --force

如果你要删除某个特定文件

复制代码
python git-filter-repo --path 大文件名字 --invert-paths --force

如果你要拆分仓库

复制代码
python git-filter-repo --subdirectory-filter 文件夹名

三、如果提示 python 不是命令,换成这个

复制代码
py git-filter-repo --strip-blobs-bigger-than 1M --force

四、使用前必须做(防止出错)

备份项目(非常重要)

复制代码
cp -r . ../my-project-backup

如果提示工作区不干净

复制代码
git add .
git commit -m "tmp"

五、清理完成后,推送到远程

git-filter-repo 在重写仓库历史时,默认会清空所有远程仓库配置(这是它的安全机制,防止你误操作覆盖远程仓库),所以你现在的本地仓库和 GitHub/Gitee 等远程仓库的连接被断开了。

需要重新关联仓库

复制代码
git remote add origin 你的仓库地址 git remote add origin https://github.com/你的用户名/你的仓库名.git

git remote add origin 原仓库地址

git remote add upstream 上游仓库地址

git push -f origin main

超级总结

从 GitHub 拉取下来之后,只需要做这一件事:

把 git-filter-repo 复制到项目目录

打开 Git Bash

运行:

复制代码
python git-filter-repo --strip-blobs-bigger-than 1M --force

✅ 搞定!

相关推荐
Harvy_没救了17 分钟前
【github爆款】Headroom:AI代理的智能上下文压缩层 —— 深度解析与洞察
人工智能·github
DogDaoDao3 小时前
【GitHub】CodeGraph 深度解析:为 AI 编程代理构建预索引代码知识图谱
人工智能·程序员·github·知识图谱·ai编程·ai agent·codegraph
疋瓞3 小时前
G内使用github实践方式
github
2601_961194023 小时前
高中英语教资资料推荐|科三大题背诵和教学设计模板
git·开源·github·开源软件·开源协议·ossinsight
程序猿阿伟3 小时前
《扣子如何让OpenClaw技能开发提速》
人工智能·git·github
_codemonster4 小时前
GitHub 删除或私有化远程仓库(Repository)教程
github
微软技术栈4 小时前
技术速递|面向初学者的 GitHub Copilot CLI:交互模式与非交互模式
人工智能·github·copilot
Hommy884 小时前
【开源剪映小助手】架构设计
开源·github·aigc·剪映小助手·视频剪辑自动化
yyuuuzz5 小时前
谷歌云基础服务的入门认知
linux·运维·服务器·数据库·人工智能·github
咖啡星人k6 小时前
MonkeyCode vs Replit vs GitHub Codespaces:云端开发环境终极对比
github