Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to revert multiple commits as part of a single commit

Tags:

git

revert

This is not a major problem, just something I want to know whether or not is possible.

Let's say we have two commits, abcd123 and wxyz789, that occur at non-adjacent, separate places, far back in a repo's history. Now let's say we want to revert them. Doing

git revert abcd123 wxyz789 

would result in two separate commits, one reverting abcd123 and the other reverting wxyz789.

This is all fine and well, but what if the mistakes we want to fix in the two commits are logically linked, and for the purposes of self-documentation we'd like to make one single commit containing one single "I broke something so now I'm reverting files x, y and z" comment? Is there a git command that does this?

(I am of course aware that it is possible to create a commit where I just manually fix all the changes and then push. This is painful for all the obbious reasons.)

like image 247
JimmidyJoo Avatar asked May 02 '12 14:05

JimmidyJoo


People also ask

How do I revert multiple commits in one commit?

Another way of reverting multiple commits is to use the git reset command.


1 Answers

You can do:

git revert abcd123 git revert --no-commit wxyz789 git commit --amend 

... and then write an appropriate commit message describing the combined effect of reverting both commits.

like image 159
Mark Longair Avatar answered Sep 16 '22 14:09

Mark Longair