How to revert multiple commits as part of a single commit

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.)

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.


In case of complicated reverts, which changes each other, the revert --no-commit might be problematic.

My simple solution was to do real revert, and the squash:

git revert <all commits>
git rebase -i

And then mark all the reverts as squash, except the first one, to create a single commit.


git revert -n <commits>
git commit

The first command will do all the reverts without create any commits and stage the final result (the -n option). After that, the commit command creates a single commit.


Need Your Help

System.Net.Sockets.SocketException on 2008R2 Server

c# smtp gmail

I have a program that I want to run on a server which is able to monitor various servers on a network and send out email notifications when certain situations involving those servers occur.

T4 templates to generate code based on current project

c# t4

In the current project in visual studio I would have a class that looks something like this

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.