0

I am trying to get commits on a particular branch in bitbucket stash.

  1. Branch was initially branched from master to develop some features
  2. after feature code was committed it was merged back to master
  3. But the branch was not deleted, so I want to use Bitbucket rest API to get the exact commits on that particular feature branch.

I tried

https://<stash-url>/stash/rest/api/1.0/projects/<project-ID>/repos/<repo-slig>/compare/commits?from=<my-target-feature-branch>&to=master

which gives me

{
"values": [],
"size": 0,
"isLastPage": true,
"start": 0,
"limit": 25,
"nextPageStart": null
}

and the other url i tried is

https://<stash-url>/stash/rest/api/latest/projects/<project-ID>/repos/<repo-slug>/commits?until=<my-target-feature-branch>&limit=100

which gives me the whole commit history from master too.

can someone please help me? I am a newbie and I'm sure there is something wrong in my understanding of API docs

jamuna
  • 93
  • 1
  • 2
  • 10
  • I know nothing about the Bitbucket API, but note that most Git commits are on many branches simultaneously. As a general rule, to limit commits, you tell Git: *get me ancestors of X, excluding ancestors of Y* where X and Y are any valid name for a commit, including branch names. Hence to list commits reachable from branch `feature` but not from branch `develop` you say: "yes to feature, no to develop" i.e. `develop..feature`. – torek Aug 26 '18 at 20:22
  • Did you used pull request? If yes then maybe you can it with /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests (there are many options there, like direction etc), and then find commits of that PR with /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}/commits? – Wojciech Piotrowiak Jul 18 '19 at 21:02

2 Answers2

1

Try:

https://<stash-url>/stash/rest/api/latest/projects/<project-ID>/repos/<repo-slug>/commits?until=<my-target-feature-branch>&limit=0&start=0

See also: https://community.atlassian.com/t5/Bitbucket-questions/Querying-the-last-commit-on-a-particular-branch-in-Bitbucket/qaq-p/577910

eeijlar
  • 1,232
  • 3
  • 20
  • 53
  • well, this also gives me commits even before the branch was created. i only want commits to this particular branch not any other commits from parent-branch – jamuna Sep 19 '18 at 17:31
  • This might help https://community.atlassian.com/t5/Bitbucket-questions/How-to-find-all-the-commits-made-on-a-branch/qaq-p/11842 – Abhishek Attri Jan 03 '20 at 13:13
0

This gives you the list of commits only for provided branch:

GET https://api.bitbucket.org/2.0/repositories/{WORKSPACE}/{REPO}/commits?include={BRANCH}&exclude=master

See BitBucket documentation for more details.

Alderven
  • 7,569
  • 5
  • 26
  • 38