Our team accidentally pushed some personal information onto Github in the form of a H2 database file. Is there any way to remove a file cleanly and completely from the server?
Simply doing git rm xxx.db
does not seem to be the answer because one can easily git reset --hard
to the head which contains the user data.
On the other hand,
git reset --hard [the head before the db file was committed]
is also not our preference because there have been more than 10 commits since the database was committed.
What should we do to remove that database file?
Answer
Read the GitHub help on removing sensitive data.
Run the following to delete the reference to the file in the entire repository – this won't delete the actual file itself:
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch' \
--prune-empty --tag-name-filter cat -- --all(Make sure to replace
with the path to the file you want removed.)Add the file to your
.gitignore
, thengit add
andgit commit
the.gitignore
file.- Run
git push origin master --force
to get the changes upstream.
There are some more steps, including cleaning up the repository and writing to GitHub itself in order to have cached data removed.
Comments
Post a Comment