Rewriting history – changing a single file
In this example, we'll see how we can use Git filter-branch to remove sensitive data from a file throughout the repository history.
Getting ready
For simplicity, we'll use a very simple example repository. It contains a few files. One among them is .credentials
, which contains a username and password. Start by cloning the repository and changing the directory, as shown in the following command:
$ git clone https://github.com/dvaske/remove-credentials.git $ cd remove-credentials
How to do it...
- As we need to modify a file when rewriting the history of this repository, we'll use the
tree-filter
option to filter branch. The.credentials
file looks as follows:username = foobar password = verysecret
- All we need ...
Get Git: Mastering Version Control 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.