threads / discuss / 50637

Git log print commits between a revision range (inclusive)

Subject: Git log print commits between a revision range (inclusive)

## tl;dr

5 messages between Mar 4, 2019 and Mar 5, 2019.

replies: 4people: 3as markdown or json

wuzhouhui· Mar 4, 2019, 07:28 UTC · lore
Hi,

I want to know how to display logs between a revision range (both start and end are inclusive). I searched it and only found[1], which doesn't resolve my problem completely, because

  git log <older hash>..<newer hash>

doesn't contains the log of <older hash>. So, how to display logs between a revision range that both start and end are inclusive?

Please CC me, thanks.
wuzhouhui· Mar 4, 2019, 07:30 UTC · re: wuzhouhui · lore

Re: Git log print commits between a revision range (inclusive)

Show 11 quoted lines
> -----Original Messages-----
> From: wuzhouhui <wuzhouhui14@mails.ucas.ac.cn>
> Sent Time: 2019-03-04 15:28:13 (Monday)
> To: git@vger.kernel.org
> Cc: 
> Subject: Git log print commits between a revision range (inclusive)
> 
> Hi,
> 
> I want to know how to display logs between a revision range (both
> start and end are inclusive). I searched it and only found [1],

Sorry for forgetting paste the link of [1]: [1] https://stackoverflow.com/questions/18595305/git-log-outputs-in-a-specific-revision-range

Show 9 quoted lines
> which doesn't resolve my problem completely, because
> 
>   git log <older hash>..<newer hash>
> 
> doesn't contains the log of <older hash>. So, how to display
> logs between a revision range that both start and end are
> inclusive?
> 
> Please CC me, thanks.
Junio C Hamano· Mar 4, 2019, 07:54 UTC · re: wuzhouhui · lore

Re: Git log print commits between a revision range (inclusive)

wuzhouhui <wuzhouhui14@mails.ucas.ac.cn> writes:
Show 7 quoted lines
> I want to know how to display logs between a revision range (both
> start and end are inclusive). I searched it and only found[1],
> which doesn't resolve my problem completely, because
>
>   git log <older hash>..<newer hash>
>
> doesn't contains the log of <older hash>.
 $ git log maint --not v2.20.0^@

gives you commits that are reachable from (i.e. ancestors of) maint, excluding those that are reachable from the set of commits denoted by v2.20.0^@.

v2.20.0^@ is how you spell the set of commits that are parents of the commit v2.20.0.

If your "range" is simple and "old" is a single-parent commit,
 $ git log <old>~1..<new>

is equivalent, because <old>~1 (i.e. the first parent of commit <old>) would be the same as <old>^@ for a single-parent commit, and because the short-hand "git log A..B" is the same as the long-hand "git log B --not A".

Rafael Ascensão· Mar 5, 2019, 23:42 UTC · re: Junio C Hamano · lore

Re: Git log print commits between a revision range (inclusive)

As Junio mentioned, "A..B" means all commits reachable from B except those reachable from A. Understanding this is just a way to say "B --not A" is important to know you can take advantage of:

`--boundary`
    Output excluded boundary commits. Boundary commits are prefixed with -.

In other words, git log --boundary <older hash>..<newer hash> should give you exactly what you asked with the small caveat it marks excluded commits differently.

Cheers, Rafael Ascensão

Junio C Hamano· Mar 5, 2019, 23:52 UTC · re: Rafael Ascensão · lore

Re: Git log print commits between a revision range (inclusive)

Rafael Ascensão <rafa.almas@gmail.com> writes:
Show 10 quoted lines
> As Junio mentioned, "A..B" means all commits reachable from B except those
> reachable from A. Understanding this is just a way to say "B --not A" is
> important to know you can take advantage of:
>
> `--boundary`
>     Output excluded boundary commits. Boundary commits are prefixed with -.
>
> In other words, git log --boundary <older hash>..<newer hash> should give you
> exactly what you asked with the small caveat it marks excluded commits
> differently.

You are correct, but only when dealing with a single strand of pearls. If the history leading to <newer> is bushy with merges, the above will give _far_ more than what was requested. The fork points of the side branches that got merged during <old>..<new> will also be shown, in addition to the <old>.

← back to recent threads