When I started my git repo I commited a few files as initial commit to it. Now, many commits later, I noticed that I included in those files a line with information which I do not want to publish (unlike the rest of the code). So I want to remove/change this one line and keep the rest of the code.
Searching around I found this solution: Insert an empty commit as initial commit (described here: Insert a commit before the root commit in Git?), do a rebase on it and then edit the old first commit via amend. Unfortunately, many cruel merge conflicts arise during rebase (as described here: git: solving conflicts caused by rebase).
Is there a different way to solve my problem or do have to rebase and edit all conflicts by hand?
Thanks in advance 🙂
Here’s a command that will remove an offending line from a file’s history in all your branches:
This checks out every revision, runs the
sedcommand on it, then commits that revision back.The
sedcommand in this case matches any lines containing the patternsensitive informationin the file namedfilenameand deletes those lines.Note: it’s good if you have a backup, and try the
sedscript on its own first to make sure it’s doing what you want, because it can take quite a while to run on a long history.