How to get two dot diff from Github API

Hello,

From this: https://help.github.com/articles/about-comparing-branches-in-pull-requests/#three-dot-and-two-dot-git-diff-comparisons

We are wondering if there is an api to get the two dot diff from two commits. 

Thanks!

4 Likes

Hi @atonyxiao,

Thanks for being here! Check out the documentation on comparing commits across time.

I hope this helps!

Hi @andreagriffiths11,

Thanks for the reply. We read the documentation and find it cannot solve our problem.

Here is an example:

We want to compare two commits with sha 

4eff613a6c96579d11dad72e63200b74afc39433 and 2b58c5f5c142588b7b944f3b79a0371378da3db6

The API gives: https://api.github.com/repos/python/mypy/compare/4eff613a6c96579d11dad72e63200b74afc39433…2b58c5f5c142588b7b944f3b79a0371378da3db6

Which is the same as three dot diff on:

https://github.com/python/mypy/compare/4eff613a6c96579d11dad72e63200b74afc39433…2b58c5f5c142588b7b944f3b79a0371378da3db6

but we wonder if we can get this through API

https://github.com/python/mypy/compare/4eff613a6c96579d11dad72e63200b74afc39433…2b58c5f5c142588b7b944f3b79a0371378da3db6

Thanks!

Hi @atonyxiao,

Thank you for taking the time to write back with more information. Unfortunately, there’s no way to do that with the GitHub REST API – you can’t pick which information will be returned. One option would be to pull each commit via the API or Git and then do a two-dot diff locally. 

I hope this helps!

1 Like

@andreagriffiths11 is it accurate to say there’s no way with the API (or with a single request) to get the actual diff of a forced push (i.e. compare old head with new head)?

1 Like

Surprised to see that go unanswered.

Edit: I had added an additional question which also went unanswered so I’ll answer it myself. I asked:

On the web, is there a way to diff this by version and all of .27 to .28?

https://github.com/alpacahq/pylivetrader

Yes:

https://github.com/alpacahq/pylivetrader/compare/v0.0.27…v0.0.28?expand=0 or

https://github.com/alpacahq/pylivetrader/compare/v0.0.27…v0.0.28?expand=0

… or with expand=1

@chrisdothtmldid you come up with any alternatives to get the actual diff of a forced push? That was exactly my use case as well, and I can’t find a good way to do it (without an order of magnitude increase in API calls)

Thanks!

Not really. Depending on your use-case there are different approaches you can take. For example, if you need to know the net change of an entire pull request after a force push, you can just compare the base branch with the head branch.

I may be able to help more if you give a bit more info on why you need this as I spent quite a lot of time around this particular issue