xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

git filter-branch

git filter-branch

# Rewrite branches
$ git filter-branch

$ git filter-branch [--setup <command>] [--subdirectory-filter <directory>]
	[--env-filter <command>] [--tree-filter <command>]
	[--index-filter <command>] [--parent-filter <command>]
	[--msg-filter <command>] [--commit-filter <command>]
	[--tag-name-filter <command>] [--prune-empty]
	[--original <namespace>] [-d <directory>] [-f | --force]
	[--state-branch <branch>] [--] [<rev-list options>…​]

https://git-scm.com/docs/git-filter-branch

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

demo

# clone the repository to your local computer.
$ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY

# Navigate into the repository's working directory.
$ cd YOUR-REPOSITORY

# filter & remove
$ git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" \
  --prune-empty --tag-name-filter cat -- --all

$ echo "YOUR-FILE-WITH-SENSITIVE-DATA" >> .gitignore
$ git add .gitignore
$ git commit -m "Add YOUR-FILE-WITH-SENSITIVE-DATA to .gitignore"

git in action

https://github.com/xgqfrms/xgqfrms/blob/c4b676cde81032acae8ca8485866527abcdfbb86/tools/WebStrom-2016.2.4.md

https://github.com/xgqfrms/xgqfrms/blob/gh-pages/tools/WebStrom-2016.2.4.md

$ git clone https://github.com/xgqfrms/xgqfrms

# git checkout gh-pages
$ cd github/xgqfrms

$ git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch tools/WebStrom-2016.2.4.md" \
  --prune-empty --tag-name-filter cat -- --all

# what's `\` & `""` means in git cli???
$ git filter-branch --force --index-filter "git rm --cached --ignore-unmatch tools/WebStrom-2016.2.4.md" --prune-empty --tag-name-filter cat -- --all

$ echo "tools/WebStrom-2016.2.4.md" >> .gitignore
$ git add .gitignore
$ git commit -m "Add YOUR-FILE-WITH-SENSITIVE-DATA to .gitignore"

testing remove-git-commit-history

https://github.com/xgqfrms/xgqfrms/remove-git-commit-history

$ git clone https://github.com/xgqfrms/remove-git-commit-history

$ cd github/remove-git-commit-history

$ git filter-branch --force --index-filter \
  "git rm --cached --ignore-unmatch tools/WebStrom-2016.2.4.md" \
  --prune-empty --tag-name-filter cat -- --all

GitHub SSH key

.po translate

https://raw.githubusercontent.com/jnavila/git-manpages-l10n/master/po/documentation.zh_HANS-CN.po

refs

https://docs.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository

https://docs.github.com/cn/github/authenticating-to-github/removing-sensitive-data-from-a-repository



©xgqfrms 2012-2025

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @   xgqfrms  阅读(518)  评论(4编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
历史上的今天:
2019-07-19 Sentry & report errors & error tracking
2019-07-19 serverless & front end
2018-07-19 ES6 Map & WeakMap & ES6 Set & WeakSet
2016-07-19 HTML5 应用程序缓存,(Application Cache),CACHE MANIFEST, manifest 文件,
2016-07-19 JavaScript 注释规范
2016-07-19 程序员面试 技术题汇总 All In One
2016-07-19 如何将自己的域名绑定到 GitHub Pages 详细教程 All In One
点击右上角即可分享
微信分享提示