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

List all commits of a specified file in oldest to newest order

From
VKVipul Kumar <kumar+git@onenetbeyond.org>
Date
Nov 5, 2021, 04:10 UTC
Message-ID
<c3932b3c-323a-39d6-26a7-ba0c3d17378b@onenetbeyond.org>
Hi,

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.

### Steps to reproduce
$ git init test
$ cd test
$ echo "Hello from foo." > a.txt
$ git add a.txt
$ git commit -m 'Initial commit'
$ git mv a.txt b.txt
$ git commit -m 'Rename a.txt to b.txt'
$ git log --follow -- b.txt
commit 55e3e6857755fe815449e787a90fe82feb174817
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:56:58 2021 +0530
     Rename a.txt to b.txt
commit f40baf5e777b2618e02805d16c950687d98356fe
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:53:35 2021 +0530
     Initial commit
$ git log --follow --reverse -- b.txt
commit 55e3e6857755fe815449e787a90fe82feb174817
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:56:58 2021 +0530
     Rename a.txt to b.txt
### Expected output

As far as I understand, using "--reverse" option along with "git log" command reverse the chronological order of the commits. So expected output of "git log --follow --reverse" command should be in oldest to newest commits order that's reverse the chronological order of "git log --follow" command's output.

$ git log --follow --reverse -- b.txt
commit f40baf5e777b2618e02805d16c950687d98356fe
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:53:35 2021 +0530
     Initial commit
commit 55e3e6857755fe815449e787a90fe82feb174817
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:56:58 2021 +0530
     Rename a.txt to b.txt
### Actual output

But when I use "--reverse" along with "--follow" option, I'm getting a single commit which points to the rename of the file.

$ git log --follow --reverse -- b.txt
commit 55e3e6857755fe815449e787a90fe82feb174817
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:56:58 2021 +0530
     Rename a.txt to b.txt
### Additional

$ git --version git version 2.33.0

First I thought "--follow --reverse" showing to me the newest commit. But later, I found out that, it always shows a single commit which points to the rename of the file.

$ echo "Hello from bar." >> b.txt
$ git add b.txt
$ git commit -m 'Update b.txt'
$ git log --follow --reverse -- b.txt
commit 55e3e6857755fe815449e787a90fe82feb174817
Author: Redacted <Redacted>
Date:   Fri Nov 5 06:56:58 2021 +0530
     Rename a.txt to b.txt

Cheers, Vipul

Next: Jeff King
Message 1 of 9 in “List all commits of a specified file in oldest to newest order”
  1. Vipul KumarNov 5, 2021
  2. Jeff KingNov 5, 2021
  3. Junio C HamanoNov 5, 2021
  4. Jeff KingNov 5, 2021
  5. Vipul KumarNov 9, 2021
  6. Ævar Arnfjörð BjarmasonNov 5, 2021
  7. Vipul KumarNov 9, 2021
  8. Ævar Arnfjörð BjarmasonNov 9, 2021
  9. Vipul KumarDec 14, 2021

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.