From: Jeff King Date: Thu, 02 Dec 2010 18:46:17 GMT Subject: Re: [PATCH] git-reset.txt: Use commit~1 notation over commit^ 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