为什么不能送手表| 梦见染头发是什么意思| 发芽土豆含有什么毒素| 嗝气是什么原因引起的| 二氧化钛是什么东西| 松针是什么| 炙是什么意思| 精英是什么意思| 腰酸背痛吃什么药| 睡眠瘫痪症是什么| 胼胝体是什么意思| wbc是什么意思| 吃什么拉什么完全不能消化怎么办| 红糖大枣水有什么功效| 开塞露是什么| 儿童肠胃感冒吃什么药效果好| 骆驼是什么品牌| 吊唁是什么意思| 人瘦肚子大是什么原因| 什么是植物人| 花木兰是什么朝代| 一个月一个并念什么| 维生素d什么牌子的好| 孕妇为什么不能参加婚礼| 呕气是什么意思| 胸口不舒服挂什么科| 8月12日是什么星座| 药品gmp是什么意思| 二米饭是什么| 后循环缺血是什么意思| 封神榜讲的是什么故事| 拾掇是什么意思| 檀木手串有什么好处| 寒气和湿气有什么区别| 龋坏是什么意思| package什么意思| 查乳房挂什么科| 大姨妈期间吃什么好| 什么牌子的点读机好| 阳痿早泄吃什么| 直视是什么意思| 男人为什么会遗精| 胃溃疡可以吃什么水果| 吃牛肉有什么好处| 什么是ps| 李白和杜甫并称什么| 男人为什么会得尿结石| 眼睛有红血丝是什么原因| 条索影是什么意思| 理发师代表什么生肖| 向日葵为什么会随着太阳转动| redline是什么牌子| 71年猪是什么命| dmd是什么病| 处女膜是什么样的| 味极鲜是什么| 嵌体是什么| 斯德哥尔摩综合症是什么意思| 绍兴本地人喝什么黄酒| 白头发多吃什么食物能变黑| jvc是什么牌子| 毛巾发黄是什么原因| 光明会到底是干什么的| 135是什么意思| 张钧甯为什么读mi| 手指甲扁平是什么原因| 七月五号是什么星座| 做肠镜需要准备什么| 李子和什么不能一起吃| 现在是什么时辰| mrv是什么检查| 长沙有什么山| 大器晚成是什么意思| zoey是什么意思| 舌根放血有什么好处| 穆斯林为什么不吃猪肉| 廉洁奉公是什么意思| 什么叫钝角| 为什么一直下雨| gopro是什么意思| 什么是屈光不正| 东方不败练的什么武功| 生日送什么礼物最好| 6月24是什么日子| 大葱喜欢什么肥料| 脂肪瘤挂什么科| 守株待兔是什么意思| 为什么拉绿色的屎| 吃什么补精子| 针灸要注意什么| 豆芽不能和什么一起吃| 庚日是什么意思啊| 来月经期间吃什么最好| 今年66岁属什么生肖的| 腺管瘤是什么| 兰蔻属于什么档次| 抱持是什么意思| 肩胛骨缝疼吃什么药| 做月子要注意什么| 心有不甘是什么意思| 做梦吃屎有什么预兆| ost什么意思| 会阴是什么| 白喉采取什么隔离| 过房养是什么意思| 两败俱伤是什么意思| 逾期不候什么意思| 垂问是什么意思| 什么减肥药最安全| 四月二十是什么星座| 双手脱皮是什么原因引起的| 血沉高是什么原因| 什么鱼蛋白质含量高| 子宫内膜脱落是什么意思| 苡字取名寓意是什么| 太阳什么的什么的| 角膜炎吃什么消炎药| 哮喘病有什么症状| 儿童湿疹用什么药| 腿麻挂什么科| 溥仪为什么没有后代| 经常放屁是什么原因| 血口喷人是什么意思| 沙中土命什么意思| 后脑勺麻木是什么征兆| 什么是值机| 牙龈肿痛吃什么水果| 牛肉补什么| 龙虎山是什么地貌| 社保跟医保有什么区别| 抗战纪念日为什么是9月3日| 为什么白带是黄色的| 工作性质是什么意思| 劳改是什么意思| 一生一世是什么意思| 好吃懒做的动物是什么生肖| 吃芒果过敏是什么症状| 什么是淡盐水| 氨咖黄敏胶囊是治什么的| 鸭子炖什么好吃| 范字五行属什么| 夜晚咳嗽是什么原因| 梦见火是什么意思| 秋五行属什么| 财迷是什么意思| 灰菜有什么功效与作用| 胃胀打嗝是什么原因| 右手背长痣代表什么| 什么叫匝道| 喝牛奶有什么好处| 列巴是什么| 发烧打冷颤是什么原因| 减脂期吃什么| 什么叫入伏| 梦见小老虎是什么预兆| 吃什么食物补气血| 2023是什么年| 潘多拉属于什么档次| 检查血液挂什么科| 六娃的能力是什么| 吃什么食物能养肝护肝| 脱臼是什么感觉| 世侄是什么意思| 什么运动瘦脸| 调羹是什么意思| 甲醛中毒吃什么药| 人为什么要呼吸| 阴茎不硬吃什么| 屁股流血是什么原因| 尿路感染为什么会尿血| 梦见抓蝎子是什么意思| 梦见自己头发白了是什么意思| 痤疮长什么样| 红楼梦贾家为什么被抄家| 大快朵颐是什么意思| 起水痘不能吃什么食物| 梦见自己被火烧是什么意思| 列装是什么意思| 银杏树的叶子像什么| 胆固醇高有什么症状| 牛骨煲什么汤对儿童好| 什么军官可以随身配枪| 吃阿司匹林有什么副作用| 什么是正装| 晚上8点半是什么时辰| 妒忌什么意思| 胡萝卜不能和什么一起吃| 狼吞虎咽是什么意思| 新生儿吐奶什么原因| 玉米除草剂什么时候打最好| 蓝绿色是什么颜色| 下嘴唇起泡是什么原因| 政治庇护是什么意思| 驾校体检都检查什么| 为什么来月经会拉肚子| 隐翅虫吃什么| 布洛芬治什么| 经典是什么意思| 月经先期是什么意思| 咖啡喝多了有什么危害| 毛重是什么| 肝郁气滞是什么意思| 去医院打耳洞挂什么科| 供观音菩萨有什么讲究| 楠字取名有什么寓意| 睡觉流鼻血是什么原因| 氮肥是什么肥| 右侧附件区囊性回声是什么意思| 钼靶是什么意思| 嘴里起血泡是什么原因| 手脚心出汗是什么原因| 什么不足| bnp是什么检查| 办理港澳通行证需要带什么证件| 手指疣初期什么样子| 划船是什么意思| 什么的长城| 二月八号是什么星座| 丁目是什么意思| 明胶是什么| 下压高是什么原因引起的| 早上起床口臭是什么原因| 夏至该吃什么| 梦见朋友死了是什么意思| 取其轻前一句是什么| 脓包疮用什么药| 头发稀少是什么原因导致的| 夏至吃什么传统美食| 螃蟹和什么食物相克| 女人眉尾有痣代表什么| 便秘吃什么药没有依赖性| 申是什么生肖| nt宝宝不配合说明什么| 全身检查要挂什么科| 2006属狗的五行缺什么| 1996年出生属什么生肖| 颈肩综合症有什么症状| 盖世英雄是什么意思| 吃汉堡为什么要配可乐| 680分能上什么大学| 月球上有什么| 子字属于五行属什么| 麒麟飞到北极会变成什么| 美的是什么牌子| 心脏右束支传导阻滞是什么意思| 阙什么意思| cv是什么意思| 见路不走是什么意思| 今年什么时候进伏天| 211是什么星座| 奇妙是什么意思| 结晶是什么意思| 6.18是什么星座| 抹茶绿配什么颜色好看| 宿便什么意思| 水瓶座是什么星象| 脐下三寸是什么地方| 赫是什么意思| 消化不良的症状吃什么药| 鲜为人知什么意思| 茎是什么意思| 外痔是什么样子的| 下颚长痘痘是什么原因| ct与核磁共振有什么区别| 百度
Table of Contents
What Is git filter-branch ?
Common Use Cases and Commands
2. Remove a Large File from History
3. Move Files into a Subdirectory
4. Delete Sensitive Data Permanently
Important Notes Before You Begin
Final Cleanup After filter-branch
Home Development Tools git Rewriting Your Entire Git History with Filter-Branch

东升汇文化产业园:鼎新文化创造 坚持文化进步

Aug 04, 2025 am 03:13 AM
git 历史修改

百度 沟通了N次……胡女士认为维权的时间成本很高。

git filter-branch is a powerful tool for rewriting Git history. It can modify the author information in the commit, delete sensitive files or large files, reconstruct directory structure, etc.; 2. You must back up the warehouse before use, and avoid rewriting history at will in the shared warehouse to avoid disrupting collaboration; 3. It is recommended to use a safer and more efficient git filter-repo instead of filter-branch, but understanding filter-branch helps to master the underlying principles and maintain old scripts; 4. After execution, you need to clean up the original references and run garbage collection to completely remove old data to ensure that sensitive information is permanently deleted.

Rewriting Your Entire Git History with Filter-Branch

Rewriting your entire Git history is a powerful but dangerous operation — and git filter-branch was historically the go-to tool for it. While newer tools like git filter-repo are now recommended, understanding how git filter-branch works helps you grap what's really happening under the hood when you rewrite history.

Here's how to use git filter-branch responsible — and what you should consider before doing it.


What Is git filter-branch ?

git filter-branch lets you rewrite commits across your entire Git history by applying filters. You can:

  • Remove sensitive data (like passwords or keys)
  • Change author names or emails globally
  • Delete large files that shouldn't have been committed
  • Split or merge directories
  • Clean up commit messages

Each commit gets rewritten from the root onward, producing a new history with altered content.

?? Warning: This changes SHA-1 hashes of all affected commits. If the repo is shared, this can break collaboration unless everyone resets their local repos.


Common Use Cases and Commands

1. Change Author Information Globally

If you've used the wrong email or name in past commits:

 git filter-branch --env-filter '
OLD_EMAIL="wrong@email.com"
CORRECT_NAME="Your Name"
CORRECT_EMAIL="correct@email.com"

if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]; then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]; then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --all

This updates both author and committer fields wherever the old email appears.

2. Remove a Large File from History

Say you accidentally committed bigfile.log :

 git filter-branch --tree-filter 'rm -f path/to/bigfile.log' --prune-empty HEAD

Or better (faster), using --index-filter :

 git filter-branch --index-filter \
'git rm --cached --ignore-unmatch bigfile.log' \
--prune-empty --tag-name-filter cat -- --all

The --index-filter is faster because it operates on the staging area without checking out each commit.

3. Move Files into a Subdirectory

To restruct your project so all old files live under legacy/ :

 git filter-branch --tree-filter '
mkdir -p legacy &&
mv * legacy/ 2>/dev/null || true
' --prune-empty -- --all

Note: Be careful with shell globs; they might miss dotfiles. Adjust accordingly.

4. Delete Sensitive Data Permanently

For removing credentials or secrets:

 git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch -r -- .env config/secrets.txt' \
--prune-empty --tag-name-filter cat -- --all

After this, also remove refs to old objects:

 rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --aggressive --prune=now

This clears loose objects and repacks the repository.


Important Notes Before You Begin

  • ? Backup your repo first. Run git clone again or zip the current state.
  • ? Don't rewrite public history lightly. If others depend on the repo, coordinate carefully — rewriting shared branches causes pain.
  • ? All downstream clones will need to rebase or reset to the new history.
  • ? Consider using git filter-repo instead — it's faster, safer, and actively maintained.

Example with git filter-repo (recommended alternative):

 # Install via pip: pip install git-filter-repo
git filter-repo --email-callback 'return email.replace(b"old@com", b"new@com")'

It avoids many pitfalls of filter-branch .


Final Cleanup After filter-branch

After running filter-branch , clean up leftover references:

 git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now --aggressive

This ensures old objects are garbage-collected and not just hidden.


Basically, git filter-branch gives you full control — but with great power comes great responsibility. Most people today should reach for git filter-repo , but knowing how filter-branch works helps debug edge cases or maintain older scripts.

The above is the detailed content of Rewriting Your Entire Git History with Filter-Branch. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72
How do I view the commit history of my Git repository? How do I view the commit history of my Git repository? Jul 13, 2025 am 12:07 AM

To view Git commit history, use the gitlog command. 1. The basic usage is gitlog, which can display the submission hash, author, date and submission information; 2. Use gitlog--oneline to obtain a concise view; 3. Filter by author or submission information through --author and --grep; 4. Add -p to view code changes, --stat to view change statistics; 5. Use --graph and --all to view branch history, or use visualization tools such as GitKraken and VSCode.

How do I delete a Git branch? How do I delete a Git branch? Jul 13, 2025 am 12:02 AM

To delete a Git branch, first make sure it has been merged or no retention is required. Use gitbranch-d to delete the local merged branch. If you need to force delete unmerged branches, use the -D parameter. Remote branch deletion uses the gitpushorigin-deletebranch-name command, and can synchronize other people's local repositories through gitfetch-prune. 1. To delete the local branch, you need to confirm whether it has been merged; 2. To delete the remote branch, you need to use the --delete parameter; 3. After deletion, you should verify whether the branch is successfully removed; 4. Communicate with the team to avoid accidentally deleting shared branches; 5. Clean useless branches regularly to keep the warehouse clean.

The top 5 most worth investing in 2025 (with latest data) The top 5 most worth investing in 2025 (with latest data) Jul 09, 2025 am 06:06 AM

The five most valuable stablecoins in 2025 are Tether (USDT), USD Coin (USDC), Dai (DAI), First Digital USD (FDUSD) and TrueUSD (TUSD).

Can I buy Dogecoin in the currency circle? How to identify scam items? Can I buy Dogecoin in the currency circle? How to identify scam items? Jul 10, 2025 pm 09:54 PM

The "Dogcoin" in the currency circle usually refers to newly issued cryptocurrencies with extremely low market value, opaque project information, weak technical foundation or even no practical application scenarios. These tokens often appear with high-risk narratives.

How to identify fake altcoins? Teach you to avoid cryptocurrency fraud How to identify fake altcoins? Teach you to avoid cryptocurrency fraud Jul 15, 2025 pm 10:36 PM

To identify fake altcoins, you need to start from six aspects. 1. Check and verify the background of the materials and project, including white papers, official websites, code open source addresses and team transparency; 2. Observe the online platform and give priority to mainstream exchanges; 3. Beware of high returns and people-pulling modes to avoid fund traps; 4. Analyze the contract code and token mechanism to check whether there are malicious functions; 5. Review community and media operations to identify false popularity; 6. Follow practical anti-fraud suggestions, such as not believing in recommendations or using professional wallets. The above steps can effectively avoid scams and protect asset security.

What is Useless Coin? Overview of USELESS currency usage, outstanding features and future growth potential What is Useless Coin? Overview of USELESS currency usage, outstanding features and future growth potential Jul 24, 2025 pm 11:54 PM

What are the key points of the catalog? UselessCoin: Overview and Key Features of USELESS The main features of USELESS UselessCoin (USELESS) Future price outlook: What impacts the price of UselessCoin in 2025 and beyond? Future Price Outlook Core Functions and Importances of UselessCoin (USELESS) How UselessCoin (USELESS) Works and What Its Benefits How UselessCoin Works Major Advantages About USELESSCoin's Companies Partnerships How they work together

How do I add a subtree to my Git repository? How do I add a subtree to my Git repository? Jul 16, 2025 am 01:48 AM

To add a subtree to a Git repository, first add the remote repository and get its history, then merge it into a subdirectory using the gitmerge and gitread-tree commands. The steps are as follows: 1. Use the gitremoteadd-f command to add a remote repository; 2. Run gitmerge-srecursive-no-commit to get branch content; 3. Use gitread-tree--prefix= to specify the directory to merge the project as a subtree; 4. Submit changes to complete the addition; 5. When updating, gitfetch first and repeat the merging and steps to submit the update. This method keeps the external project history complete and easy to maintain.

Completed python blockbuster online viewing entrance python free finished website collection Completed python blockbuster online viewing entrance python free finished website collection Jul 23, 2025 pm 12:36 PM

This article has selected several top Python "finished" project websites and high-level "blockbuster" learning resource portals for you. Whether you are looking for development inspiration, observing and learning master-level source code, or systematically improving your practical capabilities, these platforms are not to be missed and can help you grow into a Python master quickly.

See all articles
h2o是什么 barry什么意思 免疫球蛋白g是什么意思 圣诞节吃什么 腰椎间盘突吃什么药
孕妇耳鸣是什么原因引起的 皮疹是什么 什么水果对眼睛好 内热是什么意思 孟夏是什么意思
一路卷风迎大年是什么生肖 什么汤补气血效果最好 速度等于什么 凌乱是什么意思 上将相当于什么级别
孕早期生气对胎儿有什么影响 结婚送什么礼物最合适 鼻炎不能吃什么食物 舌头边上有锯齿状是什么原因 口臭是什么原因引起的
大禹姓什么hcv7jop6ns8r.cn 没有力气是什么原因hcv8jop9ns3r.cn 憨是什么意思cl108k.com 梦见鹦鹉是什么征兆hcv7jop6ns3r.cn 豆腐和什么不能一起吃sanhestory.com
吉兰巴雷综合征是什么病bfb118.com 89年的蛇是什么命fenrenren.com ao是什么意思hcv8jop1ns5r.cn 吩可以组什么词hcv8jop8ns3r.cn 胶水用什么能洗掉hcv8jop2ns0r.cn
嫡母是什么意思hcv9jop4ns2r.cn 6月16日是什么星座hcv8jop5ns3r.cn 什么是象限hcv7jop4ns8r.cn 土耳其烤肉是用什么肉hcv9jop2ns0r.cn 什么时候立秋adwl56.com
耳鸣吃什么药效果好hcv8jop4ns3r.cn 冬虫夏草生长在什么地方shenchushe.com 降钙素原是什么意思hcv8jop6ns8r.cn 如火如荼是什么意思hcv8jop2ns8r.cn 舒张压和收缩压是什么hcv8jop8ns5r.cn
百度