[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.txtfile. 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

posted @   Zhentiw  阅读(442)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 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工具
点击右上角即可分享
微信分享提示