Skip to content

Commit

Permalink
revert: allow reverting a root commit
Browse files Browse the repository at this point in the history
Although it is probably an uncommon operation, there is no
reason to disallow it, as it works just fine. It is the
reverse of a cherry-pick of a root commit, which is already
allowed.

We do have to tweak one check on whether we have a merge
commit, which assumed we had at least one parent.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed May 16, 2011
1 parent 1618073 commit fad2652
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions builtin/revert.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ static int do_pick_commit(void)
discard_cache();

if (!commit->parents) {
if (action == REVERT)
die (_("Cannot revert a root commit"));
parent = NULL;
}
else if (commit->parents->next) {
Expand Down Expand Up @@ -467,7 +465,7 @@ static int do_pick_commit(void)
strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));

if (commit->parents->next) {
if (commit->parents && commit->parents->next) {
strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
}
Expand Down

0 comments on commit fad2652

Please sign in to comment.