git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] revert: allow reverting a root commit

From
Jeff King <peff@peff.net>
Date
May 12, 2011, 11:09 UTC
Message-ID
<20110512110955.GB5292@sigill.intra.peff.net>
In-Reply-To
<20110512110855.GA5240@sigill.intra.peff.net>

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>
---
 builtin/revert.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/builtin/revert.c b/builtin/revert.c
index f697e66..1f27c63 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -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) {
@@ -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));
 		}
-- 
1.7.5.1.12.ga7abed
Previous: Sebastian SchuberthNext: Sebastian Schuberth
Message 6 of 12 in “git cherry-pick --strategy=resolve segfaults if picking a root commit”
  1. Sebastian SchuberthMay 12, 2011
  2. Jeff KingMay 12, 2011
  3. Jeff KingMay 12, 2011
  4. 1/3 cherry-pick: handle root commits with external strategiesJeff King, May 12, 2011
  5. Sebastian SchuberthMay 12, 2011
  6. 2/3 revert: allow reverting a root commitJeff King, May 12, 2011
  7. Sebastian SchuberthMay 12, 2011
  8. 3/3 t3503: test cherry picking and reverting root commitsJeff King, May 12, 2011
  9. Johannes SixtMay 12, 2011
  10. Jeff KingMay 12, 2011
  11. Jeff KingMay 16, 2011
  12. Junio C HamanoMay 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.