Sed breaking during git filter-branch

641 Views Asked by At

Has anyone successfully modified files in an Android Studio project throughout the repository history? I'm trying to remove some sensitive data that was entered mistakenly and spans several commits (it's a phone number). I'm attempting to run the following command:

git filter-branch --tree-filter "find . -name '*.java' -print0 | xargs sed -i '' -e 's/xxxxxxxxxx/0000000000/g'"

But I'm immediately getting the error

Rewrite c61760bca0273b8597299146fa5c43f984a50e3c (1/22)sed: can't read : No such file or directory
tree filter failed: find . -name '*.java' -print0 | xargs sed -i '' -e 's/xxxxxxxxxx/0000000000/g'

where xxxxxxxxxx is the number to be switched out. The files in question are stored in a deeper directory, but for some reason sed can't even find them. I'm guessing the error means it fails on the first commit because sed can't read the files? I'm unsure why, because they are definitely local.

Can anyone shed some light on my trouble? Many thanks in advance.

1

There are 1 best solutions below

3
On BEST ANSWER

You don't need to worry about obscure flags if you use the BFG, rather than git-filter-branch. The BFG is designed specifically for the case of remove unwanted data- where you don't really care where the bad data is, in what obscure file - you just want it gone.

To use the BFG, create a unwanted.txt file, containing just one line like this:

xxxxxxxxxx==>0000000000

Then run the BFG with this command:

$ java -jar bfg.jar -fi '*.java' --replace-text unwanted.txt  my-repo.git

Your entire repository history will be scanned, and all .java files (under 1MB in size) will have the substitutions performed: any matching string (that isn't in your latest commit) will be replaced.

The BFG is typically hundreds of times faster than running git-filter-branch on a big repo and the options are tailored around these two common use-cases:

  • Removing Crazy Big Files
  • Removing Passwords, Credentials & other Private data

Full disclosure: I'm the author of the BFG Repo-Cleaner.