Is there a way I could change content of a file through out all commits in git?

I am stuck in situation, where one of the config file in my project has a signing password in it and its been committed on to git since the start (Almost 800+) commits so far. I want to move the password from that config file and use it separately from now on. But my concern is the older commits still have that content and I want to update in all those. The best way I could come up with is to move it to different repo altogether and start the project from fresh . But I am curious if git has some thing which I can use to achieve the same without creating new repo excluding the file which has password. Please help.

This was added as support to tell that this is not the duplication post of this . I want to remove the content from file not delete the file from git. Hope it helps to identify it as unique.

  • How can I make git am / git apply work “fuzzy” like the patch command
  • Adding Local repository Github Desktop whole User file
  • web.config and app.config machine-specific settings in git
  • git shows that I deleted all the files in my repo and staged them for commit after I did a git pull. Why?
  • git says project description file hasn't been modified even when it is actually modified
  • Working in trunk, don't want to commit, want to move changes to branch
  • How to git cherry-pick from sibling directories?
  • Have JIRA send mails to watchers on commit from Stash on a ticket
  • Recommended workflow for public and private forks of a public GIT-SVN-created repo
  • how to easily select a single commit when a range must be specified?
  • Intellij Grails and Git
  • how to git pull/fetch local repo from remote where cloned with --share --bare
  • 3 Solutions collect form web for “Is there a way I could change content of a file through out all commits in git?”

    Sure, have a look at git filter-branch, it is made for situations like this. Which filter arguemnt you need depends on what you want to do exactly. If you want to remove the whole config file, you might want to use --index-filter, if you just want to remove the line with the password, you might want to use --tree-filter and in any way you might also want to use --tag-filter cat to get your tags moved to the rewritten commits too, otherwise they stay on the old commits.

    You can use git-filter-branch, but it might be slow or inconvenient. For you it’s easier and faster to use bfg-repo-cleaner tool. It’s not distributed with git, but really stellar and super fast compared to git-filter-branch:

    java -jar bfg-1.12.14.jar --delete-files <file> --private <git repo>

    It will automatically remove file from all branches. Tags will be reapplied to proper commits. And for several thousand commits, it will probably work few seconds 😉 --private option is there to avoid adding information about old commit ids to rewritten commit messages.

    Don’t sweat the git history. You need to invalidate and cycle the secret, even if you re-wrote the history to hide it. The secret is out, you can’t take it back.
    Focus on getting the new secret out of source control and move on.

    Git Baby is a git and github fan, let's start git clone.