How to remove file from Git history?

后端 未结 7 864
时光说笑
时光说笑 2020-11-28 03:04

Some time ago I added info(files) that must be private. Removing from the project is not problem, but I also need to remove it from git history.

I use Gi

7条回答
  •  时光取名叫无心
    2020-11-28 03:25

    • remove the file and rewrite history from the commit you done with the removed file(this will create new commit hash from the file you commited):

      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

    • now force push the repo:

      git push origin --force --all

    • now tell your collaborators to rebase.

提交回复
热议问题