Skip to content

Instantly share code, notes, and snippets.

@w0rd-driven
Created November 18, 2016 20:19
Show Gist options
  • Save w0rd-driven/60779ad557d9fd86331734f01c0f69f0 to your computer and use it in GitHub Desktop.
Save w0rd-driven/60779ad557d9fd86331734f01c0f69f0 to your computer and use it in GitHub Desktop.
BFG Repo-Cleaner --replace-text example
PASSWORD1 # Replace literal string 'PASSWORD1' with '***REMOVED***' (default)
PASSWORD2==>examplePass # replace with 'examplePass' instead
PASSWORD3==> # replace with the empty string
regex:password=\w+==>password= # Replace, using a regex
regex:\r(\n)==>$1 # Replace Windows newlines with Unix newlines
@mevers303
Copy link

Thanks!

@BarbzYHOOL
Copy link

Very useful.

regex:(?i)(barbz)==> # Matches "barbz" insensitively

@fcu423
Copy link

fcu423 commented Dec 18, 2018

Hi!

Do you know if there's anyway to use the BFG command to delete files but applying it only to an specific path in the repository?

Several files might match the regex expressions that I'm building but I would like to filter so that it only applies to the files I want.

Thanks!

@williamclot
Copy link

I found these two flags @fcu423, maybe they can help:
--filter-content-including <glob> do file-content filtering on files that match the specified expression (eg '*.{txt,properties}') --filter-content-excluding <glob> don't do file-content filtering on files that match the specified expression (eg '*.{xml,pdf}')

@farazdurrani
Copy link

For those who want to know which flavor of regex is accepted by regex, it's the one that's used with grep.

@yamunaarumugam
Copy link

Hi, is there a way to search like "PASSWORD1".

Consider commit history with the following line:
password: "PASSWORD1"

When I replace the commit history, the above line becomes,
password: "REMOVED"

Again I'm getting secrets detected in repository.

Please provide your suggestions.
Thanks in advance!

@moritztim
Copy link

@yamunaarumugam If you have this exact situation (Password: "something") and you want it to be removed, the following regular expression should work. But use an online regex tester to check if it works first

regex:(?<=Password: ")[^"]*==>REMOVED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment