I entered a curseword in my code and I pushed the code on the master branch. I pushed a few more times after that so people do not pull the bad stuff, but I can still find the curseword in the commits history.
I don't want to add the file to .gitignore
because we need that file.
Is there a way to delete the commit from history?
If it's only on your local PC (or noone checked out your changes):
git log
to find the commit you want to remove. Copy hash (the long sqeuence like: e8348ebe553102018c...).
git rebase -i [hash]~
: for example
git rebase -i e8348~
Just remove the commit you don't need and save the file.
Interactive git rebase can let you also fix the broken commit - there is no need to remove it.
If you pushed changes to the server or someone already got your changes - never change history - it'd cause serious problems for your team.