[Git] Purging History
REPO COPY
Now you've done it. You accidentally put the company's master password into one of your files. You're beginning to panic because you know that it's pretty hard to delete something forever in git. That's what you really need to do, though, or you're in big trouble. You're going to need to purge the history. First, though, make a copy of your repo in case you mess it up. Make a copy of the poodles
repository, and name it whatever you want.
git clone poodles poodles-backup
TREE FILTER
Luckily for you, the password you accidentally committed was in the master_password.txt
file. Use the filter-branch
command and remove this file from all of your commits.
git filter-branch --tree-filter 'rm -f master_password.txt'
INDEX FILTER
This repository is so large, using --tree-filter
is going to take all day. Use --index-filter
to remove master_password.txt
instead. Remember, --index-filter
will need a command that works on the staging area, which is going to be some sort of git command.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch master_password.txt'
Because --index-filter run on the staging area, so we need to add 'git' before the 'rm -f'.
FORCE
You just realized that you also have a master_username.txt
file that should probably be removed too, just to be safe. Use either technique you have learned to remove this file. Don't forget, you have a history backup from the first time you used filter-branch
. Use the correct option to force git to overwrite it.
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch master_username.txt'
PRUNING
Great! Now we're getting somewhere. There is one more problem though, you realize that some of the commits don't contain anything anymore, since you removed the password file that they referenced. You should probably use the --prune-empty
option do something to clean these out.
git filter-branch -f --prune-empty -- --all
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具