Skip to content

Commit fad2652

Browse files
peffgitster
authored andcommitted
revert: allow reverting a root commit
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1618073 commit fad2652

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

builtin/revert.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ static int do_pick_commit(void)
408408
discard_cache();
409409

410410
if (!commit->parents) {
411-
if (action == REVERT)
412-
die (_("Cannot revert a root commit"));
413411
parent = NULL;
414412
}
415413
else if (commit->parents->next) {
@@ -467,7 +465,7 @@ static int do_pick_commit(void)
467465
strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
468466
strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
469467

470-
if (commit->parents->next) {
468+
if (commit->parents && commit->parents->next) {
471469
strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
472470
strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
473471
}

0 commit comments

Comments
 (0)