Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 8

How to get two dot diff from Github API

Solved! Go to Solution.

Hello,

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

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

 

Thanks!

7 Replies
Community Manager
Message 2 of 8

Re: How to get two dot diff from Github API

Hi @aTonyXiao,

 

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

 

I hope this helps!

 


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 2
Message 3 of 8

Re: How to get two dot diff from Github API

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...2b58c5f5...

Which is the same as three dot diff on:

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

but we wonder if we can get this through API

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

 

Thanks!

 

Solution
Community Manager
Message 4 of 8

Re: How to get two dot diff from Github API

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!

 


Best,
AndreaG

Mark helpful posts with Accept as Solution to help other users locate important info. Don't forget to give Kudos for great content!

Copilot Lvl 3
Message 5 of 8

Re: How to get two dot diff from Github API

@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)?

Copilot Lvl 2
Message 6 of 8

Re: How to get two dot diff from Github API

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

Copilot Lvl 2
Message 7 of 8

Re: How to get two dot diff from Github API

@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!

Copilot Lvl 3
Message 8 of 8

Re: How to get two dot diff from Github API

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