How to do it...

  1. As we need to modify a file when rewriting the history of this repository, we'll use the tree-filter option to filter the branch. The .credentials file looks as follows:
username = foobar
password = verysecret 
  1. All we need to do is remove everything after the equals sign on each line of the file. We can use the following sed command to do this:
sed -i '' -e 's/^\(.*=\).*$/\1/' 
  1. We can now run the filter branch with the following command:
$ git filter-branch --prune-empty  --tree-filter "test -f .credentials && sed -i '' -e 's/^\(.*=\).*$/\1/' .credentials || true" -- --all 
  1. If we look at the file now, we can see that the username and password are gone:
$ cat .credentials 
username = 
password = 
  1. As we saw in the previous ...

Get Git Version Control Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.