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

Re: [PATCH] git-reset.txt: Use commit~1 notation over commit^

From
Jeff King <peff@peff.net>
Date
Dec 2, 2010, 18:46 UTC
Message-ID
<20101202184617.GA20225@sigill.intra.peff.net>
In-Reply-To
<7veia0rrew.fsf@alter.siamese.dyndns.org>
On Thu, Dec 02, 2010 at 09:55:03AM -0800, Junio C Hamano wrote:
> Perhaps we need to also fix "git name-rev master^" which currently does
> not try to reduce "master~1" to "master^".
This patch does it:
diff --git a/builtin/name-rev.c b/builtin/name-rev.c
index c946a82..417bae5 100644
--- a/builtin/name-rev.c
+++ b/builtin/name-rev.c
@@ -142,8 +142,12 @@ static const char *get_rev_name(const struct object *o)
 		int len = strlen(n->tip_name);
 		if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
 			len -= 2;
-		snprintf(buffer, sizeof(buffer), "%.*s~%d", len, n->tip_name,
-				n->generation);
+		if (n->generation == 1)
+			snprintf(buffer, sizeof(buffer), "%.*s^", len,
+				 n->tip_name);
+		else
+			snprintf(buffer, sizeof(buffer), "%.*s~%d", len,
+				 n->tip_name, n->generation);
 
 		return buffer;
 	}

but I am not sure the results are always more readable. I think "foo^"
is perhaps nicer than "foo~1". But in more complex examples, I kind of
think the ~1 is easier to read. E.g.:

  # old
  $ git name-rev 9904fadf
  9904fadf tags/v1.7.3-rc2~1^2~1

  # new
  $ git name-rev 9904fadf
  9904fadf tags/v1.7.3-rc2~1^2^

Somehow the visual appearance of "^2^" ends up being more confusing to
me than ~1^2~1, I guess because in the latter there is a regular set of
modifier-number pairs.

But I admit that is just my subjective opinion.

-Peff
Previous: Junio C HamanoNext: Junio C Hamano
Message 20 of 23 in “git-reset.txt: Use commit~1 notation over commit^”
  1. git-reset.txt: Use commit~1 notation over commit^jari.aalto@cante.net, Dec 1, 2010
  2. Drew NorthupDec 1, 2010
  3. Jari AaltoDec 1, 2010
  4. Kevin BallardDec 1, 2010
  5. Jari AaltoDec 1, 2010
  6. Kevin BallardDec 1, 2010
  7. Junio C HamanoDec 1, 2010
  8. Jari AaltoDec 1, 2010
  9. Andreas SchwabDec 2, 2010
  10. Jari AaltoDec 2, 2010
  11. Santi BéjarDec 1, 2010
  12. Jari AaltoDec 2, 2010
  13. Miles BaderDec 2, 2010
  14. Jari AaltoDec 2, 2010
  15. Drew NorthupDec 2, 2010
  16. Miles BaderDec 2, 2010
  17. jariDec 2, 2010
  18. Andreas SchwabDec 2, 2010
  19. Junio C HamanoDec 2, 2010
  20. Jeff KingDec 2, 2010
  21. Junio C HamanoDec 2, 2010
  22. Jeff KingDec 2, 2010
  23. Miles BaderDec 2, 2010

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.