I recently noticed that I had a file with sensitive information under version control in git. I have now added this file to my .gitignore list, but how can I remove all mention of it from my commit history without touching anything else? i.e., I don't want to just delete my .git
directory.
Asked
Active
Viewed 5,548 times
12

bqui56
- 2,091
- 8
- 22
- 40
2 Answers
9
Try this guide on the GitHub help site: https://help.github.com/articles/remove-sensitive-data
Specifically:
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch Rakefile' \
--prune-empty --tag-name-filter cat -- --all

twe4ked
- 2,832
- 21
- 24
-
Will this remove any trace of the sensitive file in `.git/` folder metadata?. – Jaime Hablutzel Mar 11 '20 at 04:14
3
Good question. This github remove-sensitive-data and this remove-sensitive-files-and-their-commits-from-git-history explain it.

Community
- 1
- 1

Ethan Fang
- 1,271
- 10
- 15