3

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
  • 33
  • 1
  • 3

1 Answers1

10

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
  • 3,323
  • 1
  • 29
  • 32
Mauricio Trajano
  • 2,377
  • 1
  • 17
  • 24
  • That was easy! I just added and committed the latest version of the file after deleting its history from the repository. Thanks. – phelpsw Nov 09 '14 at 20:30
  • 2
    @phelpsw, make sure to change the password(s) from that file. It is still possible that they were compromised... – Chris Nov 09 '14 at 22:30