Accidently add mongodb database link to my github

167 views Asked by At

I just realized that I forgot to add the gitignore file, as a consequence my mongodb database link is in one of my previous commmit. Could anyone help to figure out how could I rewrite that commit without deleting it ???

1

There are 1 answers

0
Ellian Carlos On

Suppose your keys are in a MY_FILE_HERE. This should do the trick:

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch MY_FILE_HERE" --prune-empty --tag-name-filter cat -- --all

Keep in mind that doing this you're changing the git history. Also remember to check if the file was correctly deleted from the remote repository history.

If you still want to retain the file, just add it to .gitignore.

Src: https://www.freecodecamp.org/news/how-to-uncommit-sensitive-files-from-git/