前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >git 删除指定文件的历史记录

git 删除指定文件的历史记录

作者头像
路过君
发布2023-11-18 15:20:03
1190
发布2023-11-18 15:20:03
举报
  1. 删除文件 src/file-to-delete.txt 替换为要删除的文件路径
代码语言:javascript
复制
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch src/file-to-delete.txt' --prune-empty --tag-name-filter cat -- --all

控制台输出,已经完成删除

WARNING: git-filter-branch has a glut of gotchas generating mangled history rewrites. Hit Ctrl-C before proceeding to abort, then use an alternative filtering tool such as ‘git filter-repo’ (https://github.com/newren/git-filter-repo/) instead. See the filter-branch manual page for more details; to squelch this warning, set FILTER_BRANCH_SQUELCH_WARNING=1. Proceeding with filter-branch… Rewrite 0bc18b0f71780c02baa7529968017c898847fae2 (47/117) (8 seconds passed, remaining 11 predicted) rm ‘src/file-to-delete.txt’ … … Ref ‘refs/heads/master’ was rewritten Ref ‘refs/remotes/origin/master’ was rewritten WARNING: Ref ‘refs/remotes/origin/master’ is unchanged

  1. 强制推送覆盖远端库 git push origin --force master

参考 https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository#purging-a-file-from-your-repositorys-history https://rtyley.github.io/bfg-repo-cleaner/

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-11-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档