git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Konstantin Khomoutov <kostix@bswap.ru>
Cc: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>, git@vger.kernel.org
Subject: Re: How to display "HEAD~*" in "git log"
Date: Thu, 7 Jul 2022 13:06:18 -0400	[thread overview]
Message-ID: <YscSigm9b8QJMuRM@coredump.intra.peff.net> (raw)
In-Reply-To: <20220706182149.gg75w6uonm4hs5af@carbon>

On Wed, Jul 06, 2022 at 09:21:49PM +0300, Konstantin Khomoutov wrote:

> > Right. The problem is that it gets the set of possible ref tips with
> > for_each_ref(), which will not include HEAD. And then worse, since the
> > argument to "--refs" is a pattern, it matches junk like origin/HEAD.
> 
> Do I assume correctly that `git for-each-ref HEAD` does nothing, successfully,
> for the very same reason?

Yes.

> If so, I wonder if this should be somehow reflected in the docs.
> I mean, I have always maintained an impression that things like HEAD,
> ORIGIN_HEAD, FETCH_HEAD etc are also "refs" - because they, well, reference
> commits or branches.
> 
> The gitglossary manual page of my Git 2.30.2 states that
> 
> | ref
> |   A name that begins with refs/ (e.g. refs/heads/master)
> | <...>
> |   There are a few special-purpose refs that do not begin with refs/.
> |   The most notable example is HEAD.
> 
> which suggests that HEAD is a ref.

Yeah, I think the situation around those top-level names
is...complicated. They act like refs when you name them, but they are
often omitted from iteration of refs. And yet many spots (e.g.,
"rev-list --all") will include them explicitly. Documentation aside, I
would not be surprised if there are still places in the code itself
where there are inconsistencies. I feel like we've had a number of
"oops, include HEAD in this corner case" patches pop up over the years.
Maybe we've gotten them all now?

All of which is to say: you're definitely not wrong, but I'm not sure
what simple documentation change would be helpful. The handling of HEAD
in each specific situation could be mentioned in their respective
documentation spots, but identifying all of those is tough. Possibly the
glossary entry should say something like:

  Note that HEAD is sometimes includes in sets of refs (e.g., in `git
  rev-list --all`) and sometimes not (e.g., in `git for-each-ref`).

but that may be too vague to be helpful to anybody.

-Peff

  reply	other threads:[~2022-07-07 17:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05  7:11 How to display "HEAD~*" in "git log" wuzhouhui
2022-07-05  9:25 ` Konstantin Khomoutov
2022-07-05  9:30   ` Konstantin Khomoutov
2022-07-05  9:36     ` wuzhouhui
2022-07-06 12:38       ` kostix
2022-07-06 14:38   ` Jeff King
2022-07-06 16:28     ` Konstantin Khomoutov
2022-07-06 16:49       ` Jeff King
2022-07-06 18:21         ` Konstantin Khomoutov
2022-07-07 17:06           ` Jeff King [this message]
2022-07-06 17:31     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YscSigm9b8QJMuRM@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=kostix@bswap.ru \
    --cc=wuzhouhui14@mails.ucas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).