2

We want to get a difference between two GitLab/GitHub branches through REST API. We saw Git supports a command to do that but it seems they don't support for REST API. Is there any API support for this?

git diff --name-status firstbranch..yourBranchName

git diff --name-status origin/develop..origin/master

Showing which files have changed between two revisions

TonyTran
  • 67
  • 1
  • 9

1 Answers1

4

GitHub has dedicated URL (non-REST) for comparing branches.
Example:

https://github.com/octocat/linguist/compare/master...octocat:an-example-comparison-for-docs

Same for GitLab:

https://gitlab.com/gitlab-org/gitlab-foss/compare?from=master&to=master

Although it can be different from a git diff.


The REST API for GitHub would be: "Compare two commits"

GET /repos/:owner/:repo/compare/:base...:head

The response also includes details on the files that were changed between the two commits.
This includes the status of the change (for example, if a file was added, removed, modified, or renamed), and details of the change itself.
For example, files with a renamed status have a previous_filename field showing the previous filename of the file, and files with a modified status have a patch field showing the changes made to the file.

For GitLab: compare branch API

GET /projects/:id/repository/compare?from=master&to=feature
VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
  • Thank you for your information. That is what I need. – TonyTran Nov 25 '19 at 19:39
  • Hi VonC, do you know how to compare branch API for GitHub? – TonyTran Nov 25 '19 at 20:14
  • 1
    @TonyTran It is https://developer.github.com/v3/repos/commits/#compare-two-commits: Both `:base` and `:head` must be branch names in `:repo`. In other words, if `:base` and `:head` are *branch* names instead of commits *SHA1*, ... you are comparing branches. – VonC Nov 25 '19 at 22:25