删除github项目历史版本中的敏感文件

on under auxilary
1 minute read

Steps

eg.删除https://www.github.com/3xp10it/MyToolKit项目历史版本中敏感文件

1.cd /tmp && git clone https://github.com/dxa4481/truffleHog.git && cd truffleHog
2.pip3 install -r requirements.txt
3.python3 truffleHog.py https://www.github.com/3xp10it/MyToolKit
    or
  python3 truffleHog.py https://github.com/3xp10it/MyToolKit.git
  此时找到了有敏感密码的文件my_bing_domains_v1_alone.py
4.cd /tmp && git clone https://github.com/3xp10it/MyToolKit.git && cd MyToolKit
5.cp my_bing_domains_v1_alone.py /tmp/
  这里是为了备份这个有敏感密码的文件
6.git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch my_bing_domains_v1_alone.py' --prune-empty --tag-name-filter cat -- --all
  这里是为了删除所有commit中的my_bing_domains_v1_alone.py文件
7.git push origin --force --all
8.git push origin --force --tags
9.git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
10.git reflog expire --expire=now --all
11.git gc --prune=now
12.python3 /tmp/truffleHog/truffleHog.py https://www.github.com/3xp10it/MyToolKit
  这里是为了验证是否成功清除历史版本中的敏感文件
13.如果有需要,将备份的my_bing_domains_v1_alone.py有关密码的部分代码修改成没有明文密码后上传到github 
    cp /tmp/my_bing_domains_v1_alone.py /tmp/MyToolKit/
    cd /tmp/MyToolKit
    git add .
    git commit -a -m "clean passwords"
    git push -u origin master
    如果没有必要将my_bing_domains_v1_alone.py文件上传则这一步不需要,例如my_bing_domains_v1_alone.py文件是一个纯
    配置文件而没有关键代码的时候,这时直接将所有历史版本中的该文件删除即可
14.done

Reffer

https://help.github.com/articles/removing-sensitive-data-from-a-repository/
git, github, truffleHog
home
github
archive
category