从github删除某个文件的提交历史。

一、当我们操作失误,把账号、密码提交到github的时候,比如提交到abc.txt文件:

  1. 可以先修改abc.txt文件把账号密码去掉,之后提交。
  2. 然后把abc.txt文件的历史记录删除掉。
    下面就说一下怎么删除abc.txt文件的历史记录。

二、删除文件的历史记录。

根据github的帮助文档,删除文件的历史记录可以有2种方式。

  • 使用git filter-branch命令的方式。
  • 使用 BFG 开源工具。
    由于BFG 开源工具比较快速,所以下面我使用这种方式。操作步骤如下:
1、下载BFG的jar包。

去BFG的官方地址下载:https://rtyley.github.io/bfg-repo-cleaner/

2、把本地的所有仓库都清除。

比如我要删除https://github.com/xxxx/deleteFile.git 库的abc.txt文件的历史记录,其实就是重写deleteFile.git仓库的历史记录。
需要把其他地方clone下载的代码都移除掉。避免删除abc.txt文件的历史记录之后其他地方pull出现冲突。

3、依次执行下面的命令。
# 拉取代码镜像
$ git clone --mirror https://github.com/xxxx/deleteFile.git
# 删除abc.txt的历史记录
$ java -jar bfg-1.13.0.jar --delete-files abc.txt deleteFile.git
$ cd deleteFile.git
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
# 推送到远程仓库
$ git push

参考文章: https://blog.youkuaiyun.com/ysy950803/article/details/53383582 https://www.jianshu.com/p/573c1d2fe9fd https://rtyley.github.io/bfg-repo-cleaner/ https://github.com/rtyley/bfg-repo-cleaner https://github.com/IBM/BluePic/wiki/Using-BFG-Repo-Cleaner-tool-to-remove-sensitive-files-from-your-git-repo

转载于:https://my.oschina.net/kunBlog/blog/3096542

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值