Voloda2
Voloda2

Reputation: 12617

git: How do I delete only fifth commit

I have for example 10 commits. I want to delete fifth commit forever. How do I delete only fifth commit.

Upvotes: 1

Views: 115

Answers (2)

Paolo Capriotti
Paolo Capriotti

Reputation: 4072

Say your commit has SHA1 abc123, you can do for example:

git rebase -i abc123^

delete the first line, save and quit. This will replay the whole history since that commit, so it can create conflicts, which you'll need to resolve by hand.

Upvotes: 5

RJFalconer
RJFalconer

Reputation: 11731

git rebase -i HEAD~5

In the text editor that comes up delete the rogue commit, then save and exit.

You may find a guide to interactive rebase helpful

Upvotes: 4

Related Questions