Git rev-list is it possible to output in in reverse order using GIT command only not bash?

230 views Asked by At

trying to get only one result from selected commits returns the same output regardless of output order.

TOTAL LIST LENGTH 130 COMMITS

The result is the same, but the list is different

showing reduced results :

$ git rev-list  --reverse origin/a..origin/b -10
c4fe26e8ebc8a2ceb0129a6f7318b08d18126baa
fd302babdae3338a2d780b529ec8499867d1c330
d24b219372ff87ada2c196857f47f7a9c61f1fad
1eaf20b79e69ae4d729a2679bdc40f6b2d22958f
6a76950fd9eee705ed813aec0c44ac58ff3a030c
058e793dbcd507861880b21aacf2dd07d2b079ff
f8bb9225c4101bf1340e35abd609e526d2bde2c1
a01e72042582337ff74f64caa0e5a25ceeba6c8d
bc88772e4cb3be926639da6d71a57aaef507cbf0
315f11516b98454cb8732ac57b9cc53dff9460b5


$ git rev-list  origin/a..origin/b -10
315f11516b98454cb8732ac57b9cc53dff9460b5
bc88772e4cb3be926639da6d71a57aaef507cbf0
a01e72042582337ff74f64caa0e5a25ceeba6c8d
f8bb9225c4101bf1340e35abd609e526d2bde2c1
058e793dbcd507861880b21aacf2dd07d2b079ff
6a76950fd9eee705ed813aec0c44ac58ff3a030c
1eaf20b79e69ae4d729a2679bdc40f6b2d22958f
d24b219372ff87ada2c196857f47f7a9c61f1fad
fd302babdae3338a2d780b529ec8499867d1c330
c4fe26e8ebc8a2ceb0129a6f7318b08d18126baa

$ git rev-list --max-count=1  origin/a..origin/b
315f11516b98454cb8732ac57b9cc53dff9460b5


$ git rev-list --reverse --max-count=1 origin/a..origin/b
315f11516b98454cb8732ac57b9cc53dff9460b5

List commits that are reachable by following the parent links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.

the command i use

git rev-list --max-count=1 $TARGET_BRANCH..$BASE_BRANCH

from documentation

Note that these are applied before commit ordering and formatting options, such as --reverse.

- -n --max-count= Limit the number of commits to output.

using the following git version

git version 2.39.0.windows.1

2

There are 2 answers

4
j6t On

The cited section from the documentation explains that the meaning of

git rev-list --max-count=1 --reverse $TARGET_BRANCH..$BASE_BRANCH

is:

  1. Collect commits in the range $TARGET_BRANCH..$BASE_BRANCH in the usual way.

  2. Truncate the collect list after the first entry (--max-count=1).

  3. List the remaining commit in reverse order (--reverse).

Of course, if the list has only one entry, the printed result looks the same regardless if printed forward or in reverse.

3
jthill On

As the docs you link say, git rev-list's --max-count is applied very early, before --reverse.

To get the effect you're asking for, use existing tools. git rev-list origin/a..origin/b | tail -1 to get the last entry.