Removing private information from old Git commits

前端 未结 2 1750
一向
一向 2021-02-13 09:00

I have a project versioned with Git that I\'d like to make open source, but it has some private information in it that is specific to the environment in which it was originally

2条回答
  •  执笔经年
    2021-02-13 09:37

    I'd recommend using the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for removing private data from Git repos.

    The usage instructions give the steps in more detail, but the core bit is just: download the BFG's jar (needs Java 6 or above) and run this command:

    $ java -jar bfg.jar  --replace-text replacements.txt  my-repo.git
    

    The replacements.txt file should contain all the substitutions you want to do, in a format like this (one entry per line - note the comments shouldn't be included):

    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
    

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

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

提交回复
热议问题