Find the commits not coming from a "pull request"

Viewed 43

Not being "pull request" something standard from git it is widely used as a good practice and it is used by default but .... I have an utility that generates documentation based on the fact all the changes that are deployed "come" from a pull request and I am wondering if there is an easy way to detect situations where that's not the case, where commits have been committed directly to "master"

For example in a diagram like that:

*    c1 (pull request)
|\
| *  c2
| *  c3
*/
|
*    c4
|

I would like to be able to detect c4.

Thanks!

1 Answers

In this graph

*       f484d1c 2020-02-29 (HEAD -> master)
|\
| *     e618633 2020-02-29 (tag: tag_b2, b2)
* |     d141ac2 2020-02-29
|/
*       5072a40 2020-02-29
|\
| *     e9446d3 2020-02-29 (tag: tag_b1, b1)
* |     9508020 2020-02-29 (tag: tag_m2)
|/
*       8bd3257 2020-02-29 (tag: tag_m1)

Get the "direct" children (not from merge)

git log --first-parent --pretty=format:"%h" tag_m1..HEAD
f484d1c
d141ac2
5072a40
9508020

Now get all the commits

git log --pretty=format:"%h" tag_m1..HEAD
f484d1c
d141ac2
e618633
5072a40
9508020
e9446d3

If we compare both results (eg. with comm) we can get the commits

Related