git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Vipul Kumar <kumar+git@onenetbeyond.org>
Cc: git@vger.kernel.org
Subject: Re: List all commits of a specified file in oldest to newest order
Date: Fri, 5 Nov 2021 04:17:49 -0400	[thread overview]
Message-ID: <YYTorS1DiuTXv0/V@coredump.intra.peff.net> (raw)
In-Reply-To: <c3932b3c-323a-39d6-26a7-ba0c3d17378b@onenetbeyond.org>

On Fri, Nov 05, 2021 at 04:10:31AM +0000, Vipul Kumar wrote:

> I want to list all commits (including renames) of a specified file in oldest
> to newest order. But when I run "git log --follow --reverse --
> <path/to/the/file>" command, I'm getting a single commit, which points to
> the "rename of the file". This behavior is weird to me because I expected to
> get list of all commit in oldest to newest order, whereas "git log --follow
> -- <path/to/the/file>" command works as expected.

This has to do with the hacky way --follow is implemented. We don't
compute the full set of commits to show ahead of time, but rather as we
traverse, we change which pathspec we'll match when we hit a commit that
has a rename. Whereas --reverse is applied before we even start the main
traversal, and instead collect all possible commits and then walk them
in reverse order.

So the very first commit we'll look at for --follow is the one that
created the file from the rename, at which point we'll start looking
only for the old name. But of course all of the other commits post-date
the rename, so they don't use that old name.

So yes, it's a bug in the sense that the behavior is nonsense and it
doesn't work as one might expect. But it's also the hacky "--follow"
working as designed, and is just a limitation of its approach. It would
need to be rewritten completely to work correctly.  Arguably we should
at least disallow the combination of --reverse and --follow for now, as
it will never help (OTOH, if there is nothing to follow it should behave
OK, and I suspect some people and scripts may add --follow "just in
case").

As a workaround, you can get what you want by two separate traversals:
one to collect the commits via --follow, and then another to actually
show them (but without doing any further walking). Like:

  git log --follow --format=%H -- $your_file |
  git log --stdin --no-walk --reverse [--oneline, -p, etc]

-Peff

  parent reply	other threads:[~2021-11-05  8:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-05  4:10 List all commits of a specified file in oldest to newest order Vipul Kumar
2021-11-05  8:13 ` Ævar Arnfjörð Bjarmason
2021-11-09  3:35   ` Vipul Kumar
2021-11-09  9:42     ` Ævar Arnfjörð Bjarmason
2021-12-14  3:58       ` Vipul Kumar
2021-11-05  8:17 ` Jeff King [this message]
2021-11-05 18:49   ` Junio C Hamano
2021-11-05 23:26     ` Jeff King
2021-11-09  5:24   ` Vipul Kumar

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=YYTorS1DiuTXv0/V@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=kumar+git@onenetbeyond.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).