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

[RFC/PATCH 1/2] Introduce CHERRY_HEAD

From
Jay Soffian <jaysoffian@gmail.com>
Date
Feb 15, 2011, 21:23 UTC
Message-ID
<1297805034-3512-2-git-send-email-jaysoffian@gmail.com>
In-Reply-To
<1297805034-3512-1-git-send-email-jaysoffian@gmail.com>
When a cherry-pick conflicts git advises to use:
 $ git commit -c <original commit id>

to preserve the original commit message and authorship. Instead, let's record the original commit id in CHERRY_HEAD and advise to use:

  $ git commit -c CHERRY_HEAD
In the next commit, we teach git to handle the '-c CHERRY_HEAD' part.
---
 branch.c         |    1 +
 builtin/commit.c |    1 +
 builtin/revert.c |   23 ++++++++++++++++++++---
 3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/branch.c b/branch.c
index 93dc866..81bbf95 100644
--- a/branch.c
+++ b/branch.c
@@ -217,6 +217,7 @@ void create_branch(const char *head,
 
 void remove_branch_state(void)
 {
+	unlink(git_path("CHERRY_HEAD"));
 	unlink(git_path("MERGE_HEAD"));
 	unlink(git_path("MERGE_RR"));
 	unlink(git_path("MERGE_MSG"));
diff --git a/builtin/commit.c b/builtin/commit.c
index 03cff5a..8850621 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1424,6 +1424,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		die("cannot update HEAD ref");
 	}
 
+	unlink(git_path("CHERRY_HEAD"));
 	unlink(git_path("MERGE_HEAD"));
 	unlink(git_path("MERGE_MSG"));
 	unlink(git_path("MERGE_MODE"));
diff --git a/builtin/revert.c b/builtin/revert.c
index dc1b702..c373e69 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -248,6 +248,22 @@ static void set_author_ident_env(const char *message)
 			sha1_to_hex(commit->object.sha1));
 }
 
+static void write_cherry_head(void)
+{
+	int fd;
+	struct strbuf buf = STRBUF_INIT;
+
+	strbuf_addf(&buf, "%s\n", sha1_to_hex(commit->object.sha1));
+
+	fd = open(git_path("CHERRY_HEAD"), O_WRONLY | O_CREAT, 0666);
+	if (fd < 0)
+		die_errno("Could not open '%s' for writing",
+			  git_path("CHERRY_HEAD"));
+	if (write_in_full(fd, buf.buf, buf.len) != buf.len)
+		die_errno("Could not write to '%s'", git_path("CHERRY_HEAD"));
+	close(fd);
+}
+
 static void advise(const char *advice, ...)
 {
 	va_list params;
@@ -269,9 +285,10 @@ static void print_advice(void)
 	advise("after resolving the conflicts, mark the corrected paths");
 	advise("with 'git add <paths>' or 'git rm <paths>'");
 
-	if (action == CHERRY_PICK)
-		advise("and commit the result with 'git commit -c %s'",
-		       find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+	if (action == CHERRY_PICK) {
+		write_cherry_head();
+		advise("and commit the result with 'git commit -c CHERRY_HEAD'");
+	}
 }
 
 static void write_message(struct strbuf *msgbuf, const char *filename)
-- 
1.7.4.5.g9affb
Previous: Jay SoffianNext: Junio C Hamano
Message 2 of 27 in “CHERRY_HEAD”
  1. 0/2 CHERRY_HEADJay Soffian, Feb 15, 2011
  2. 1/2 Introduce CHERRY_HEADJay Soffian, Feb 15, 2011
  3. Junio C HamanoFeb 15, 2011
  4. Jonathan NiederFeb 15, 2011
  5. Junio C HamanoFeb 15, 2011
  6. Bert WesargFeb 15, 2011
  7. Junio C HamanoFeb 15, 2011
  8. Bert WesargFeb 15, 2011
  9. Jay SoffianFeb 15, 2011
  10. Jonathan NiederFeb 15, 2011
  11. 2/2 Teach commit to handle CHERRY_HEAD automaticallyJay Soffian, Feb 15, 2011
  12. Jay SoffianFeb 15, 2011
  13. Junio C HamanoFeb 15, 2011
  14. Jonathan NiederFeb 15, 2011
  15. Jay SoffianFeb 15, 2011
  16. Jonathan NiederFeb 15, 2011
  17. Jay SoffianFeb 16, 2011
  18. Jonathan NiederFeb 16, 2011
  19. Documentation: clarify interaction of --reset-author with --authorJonathan Nieder, Feb 16, 2011
  20. Junio C HamanoFeb 16, 2011
  21. Ævar Arnfjörð BjarmasonFeb 15, 2011
  22. Junio C HamanoFeb 15, 2011
  23. Jay SoffianFeb 15, 2011
  24. Ævar Arnfjörð BjarmasonFeb 15, 2011
  25. Jay SoffianFeb 15, 2011
  26. Miles BaderFeb 16, 2011
  27. Christian CouderFeb 17, 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.