Git revert multiple commits - How to revert multiple git commits?

734    Asked by LeahHarris in Devops , Asked on Jun 12, 2021

I have a git repository that looks like this:

A -> B -> C -> D -> HEAD

I want the head of the branch to point to A, i.e. I want B, C, D, and HEAD to disappear and I want head to be synonymous with A.

It sounds like I can either try to rebase (doesn't apply, since I've pushed changes in between), or revert. But how do I revert multiple commits? Do I revert one at a time? Is the order important?

Answered by Josh Ellison

The following command will git revert multiple commits with only one commit.

  $ git revert --no-commit HEAD~3..


Your Answer

Interviews

Parent Categories