4

I have a single file in a git repo and it contains sensitive information. I've removed this information in the latest commit. Now I want to delete all previous versions of this file from the git repository. How can this be done?

I believe it can be done with git-filter-branch but I haven't come across an example I can wrap my head around yet.

phelpsw
  • 43
  • 1
  • 3

1 Answers1

12

Quoting the git documentation:

Suppose you want to remove a file (containing confidential information or copyright violation) from all commits:

git filter-branch --tree-filter "rm filename" HEAD

However, if the file is absent from the tree of some commit, a simple rm filename will fail for that tree and commit. Thus you may instead want to use rm -f filename as the script.

So you want to run git filter-branch --tree-filter "rm -f filename" HEAD to erase all history of that file

Jöcker
  • 5,281
  • 2
  • 38
  • 44
Mauricio Trajano
  • 2,677
  • 2
  • 20
  • 25