惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

游牧血液

2026 年春节江西之旅 让 AI 写代码,它派了支咨询团队来 在 AI 时代,应该选择什么编程语言? 在 AI 时代,博客该怎么写? 深入理解 ISO 8601 时间间隔表示法 在 CentOS 7 上,使用 Let's Encrypt 安装免费的 HTTPS 证书 可组合数据系统之路:对过去 15 年和未来的思考 交换友情链接 MacOS 下解决 Edge 浏览器侧边栏无法关闭的问题 你使用什么作为数据库的 ID? HTTP API 的错误响应标准 只需要一个文件,在本机跑起 ChatGPT 聊一聊 Node 技术栈 个人网站迁移到 Astro 静态网站生成器 Gridsome 介绍 编程命名规范 升级到 iOS 14.2 后,Google Authenticator 挂了 SaaS 数据库架构选择 GitHub 宣布私有仓库支持无限协作者,核心功能全部免费 新一代通信协议:RSocket Let’s Encrypt 撤销 300 万个证书,检查你的证书是否在其中 为 HTTP API 接口增加统一请求日志 | 游牧血液 我编程 20 年的指导原则 | 游牧血液 如何做 HTTP 接口的访问控制 | 游牧血液 什么是移动原生业务软件(MNBA:Mobile Native Business Applications) | 游牧血液 JDK 的另一个选择:OpenJDK with Eclipse OpenJ9 分享开发多个线上项目后总结的 HTTP 接口设计方案 Flutter 集成友盟统计 Hugo 简明教程 Flutter 开发时,idevice_id 不能执行问题的解决 另一个静态网站生成器:Hugo
使用 BFG Repo-Cleaner 修改 Git 提交历史 | 游牧血液
2020-03-16 · via 游牧血液
Cover

目录

展开目录

为什么要修改 Git 提交历史

修改 Git 历史,一般有以下两个原因:

  • 删除密码、API Key 等敏感数据,因为即使你在最新的提交删除了他们,在历史提交里也存在;
  • 删除超大文件。

超大文件问题经常出现在当你从一个 Git 托管网站换到另一个时,常因为后者不支持大文件,导致推送不上去。即使最新版删除了大文件,因为大文件存在在历史中,依然不能推送。

目前我测试几个网站的文件大小限制:

操作步骤

本文演示删除历史中的大文件步骤。

安装 bfg

如果是 MacOS,直接安装即可:

brew install bfg

如果是其他系统,可以下载 1.13.0 版的 jar 包,并将下面命令中的 bfg 替换成 java -jar path/to/bfg-1.13.0.jar

克隆仓库

git clone --mirror git@xxxxxx.com:jitao/project.git

这里使用 --mirror 参数,表示克隆出来的是一个 bare 仓库。

这一步最好备份一下仓库。

改历史

bfg --delete-files home.mp4 project.git

删除 home.mp4 这个文件,注意参数只能是文件名,不包含路径。如果传入一个路径,会报错:

Error: *** Can only match on filename, NOT path *** - remove '/' path segments

正常运行大概输出如下:

Using repo : /Users/jitao/workspace/project.git

Found 527 objects to protect
Found 2 commit-pointing refs : HEAD, refs/heads/master

Protected commits
-----------------

These are your protected commits, and so their contents will NOT be altered:

 * commit 9bbd9c4e (protected by 'HEAD')

Cleaning
--------

Found 336 commits
Cleaning commits:       100% (336/336)
Cleaning commits completed in 435 ms.

Updating 1 Ref
--------------

	Ref                 Before     After
	---------------------------------------
	refs/heads/master | 9bbd9c4e | bc0c11c6

Updating references:    100% (1/1)
...Ref update completed in 24 ms.

Commit Tree-Dirt History
------------------------

	Earliest                                              Latest
	|                                                          |
	.............................DDDDDmmmmmmmmmmmmmmmmmmmmmmmmmm

	D = dirty commits (file tree fixed)
	m = modified commits (commit message or parents changed)
	. = clean commits (no changes to file tree)

	                        Before     After
	-------------------------------------------
	First modified commit | 4021098d | ce77dc85
	Last dirty commit     | d73ece33 | e26922da

Deleted files
-------------

	Filename   Git id
	------------------------------
	home.mp4 | 8ab9914d (114.1 MB)


In total, 187 object ids were changed. Full details are logged here:

	/Users/jitao/workspace/project.git.bfg-report/2020-03-15/15-02-30

BFG run is complete! When ready, run: git reflog expire --expire=now --all && git gc --prune=now --aggressive

信息的最后 bfg 还夹带了点私货:

--
You can rewrite history in Git - don't let Trump do it for real!
Trump's administration has lied consistently, to make people give up on ever
being told the truth. Don't give up: https://www.rescue.org/topic/refugees-america
--

呵呵。

清理仓库

cd project.git
git reflog expire --expire=now --all && git gc --prune=now --aggressive

推送

git push

参考文章