You'll need to rewrite your branch history, which may break a lot of things.
To rewrite history, use rebase:
git rebase -i <commit-hash-with-the-oopsie>~1
Then:
- Replace "pick" with "edit" on the first line of the opened
git-rebase-todo
file
- Save-exit git-rebase-todo
- Change or delete the file with the oopsie
git add
the file with the oopsie
- Run
git rebase --continue
and wait for it to finish.
When it finishes, you'll have a differing branch history that doesn't commit an oopsie.
Caveats (there are many)
- Having more than one branch complicates things, and any related branches with the old oopsie commit will also need to be reconstructed. Find them using the following command:
git branch --contains <commit-hash-with-the-oopsie>
Same goes with tags:
git tag --contains <commit-hash-with-the-oopsie>
If your branch contains merges, they'll effectively be flattened into a linear git history, and any conflict resolutions will need to be re-done. There is a way to preserve merges during rebase
, but I've not gotten it to work very well.
Your name will be the committer on all the commits after <commit-hash-with-the-oopsie>
. The commit date will also change.
The commit can persist in .pack
files inside the git objects directory until anything that references it is more than 2 weeks old and you run git gc
. You can force git's hand in this using git reflog expire --stale-fix --expire-unreachable=now --all --rewrite && git gc --aggressive && git prune