Undo (not revert) historic local commit?

Viewed 82

How can I undo a commit that should never have been made, when 17 commits have been made afterwards?

Background: a colleague in my team worked solo for a month, and now its time to merge their branch to the master. However, one of the commits contains a single file that's far too big to upload to GitHub. They tried reverting the commit but GitHub still wants to upload the file in order to remove it again, so we can't just revert the initial faulty commit.

So how can we undo that commit as if it never happened? We have GitBash and Github Desktop.

1 Answers

You can do an interactive rebase to delete the one faulty commit.

Caution: you will change history by that and may introduce surprises if someone else has already pulled the branch.

git checkout colleagues-feature-branch
git rebase -i develop

Then in the textfile that opens, mark the desired commit with drop (instead of pick). Save and exit.

Related