Search code examples
gitgithubazure-devopsdevopsazure-git-deployment

pull requests between two tags in git


Is there a way to get pull requests between two tags on a specific branch.

Right now, I am using git log to do this. But, seems like this is bringing pull requests created before the first tag(PreviousVersion).

git log --grep 'Merged PR' --oneline $CurrentVersion...$PreviousVersion --pretty=format:\"%s\"|cut -d':' -f 1|cut -d' ' -f3

Can you help.


Solution

  • $CurrentVersion...$PreviousVersion does not mean "between these two commits". It means "any commits reachable by ONLY $CurrentVersion or ONLY $PreviousVersion" so you might get some commits before $PreviousVersion.

    r1...r2 is called symmetric difference of r1 and r2 and is defined as r1 r2 --not $(git merge-base --all r1 r2). It is the set of commits that are reachable from either one of r1 (left side) or r2 (right side) but not from both.

    Instead, use $PreviousVersion..$CurrentVersion (two dots). This also isn't quite "between these two commits" because Git history is not linear. It means "commits reachable by $CurrentVersion and not reachable by $PreviousVersion" which is usually what you want.

    Using this little example repository...

    A
    |
    B  [current]
    |
    C
    |
    |  1 [previous]
    |  |
    |  2
    | /
    D
    |
    E
    
    • current can see B, C, D, E.
    • previous can see 1, 2, D, E.

    current...previous will show B, C (only reachable by current) and 1, 2 (only reachable by previous).

    previous..current will show only B and C.

    current..previous will show only 1 and 2.

    See Revision Selection in Pro Git for examples.