Anonymise a local git repository?
Asked Answered
J

2

7

I have a local git repository that I've done quite a bit of work on, with a number of commits that I'd like to retain. Unfortunately, while the code is reasonable reusable, I included some sensitive data (database names/user/passwords) in a very early commit. I would like to change the entire history to anonymise the sensitive data, while retaining the general history structure. Is this possible? If so, how?

Jacquejacquelin answered 10/6, 2012 at 12:7 Comment(0)
S
5

I think this will help:

Shangrila answered 10/6, 2012 at 12:25 Comment(1)
Yes. History re-writing is they key. I made a backup repo (just in case), and then ran git filter-branch --tree-filter 'sed -i "s/sensitive data/clean data/g *' HEAD, and that removed everything from the whole tree. Thanks for the pointer!Jacquejacquelin
N
0

Remove them from the repository, then commit. You then need to squash all the commits from when the files were added to when they were removed. You can see a good explanation about that here which in short suggests using git rebase -i.

Nauseate answered 10/6, 2012 at 12:25 Comment(1)
I am aware I can squash commits, but that will remove the history I was talking about.Jacquejacquelin

© 2022 - 2024 — McMap. All rights reserved.