We are trying to find a way to download a single file from a Bitbucket project using the REST API at a specific commit. Currently, we have the ability to download a file at a specific branch:
Note that the end of the URL, when decoded, contains the query parameter at=refs/heads/master
, which refers to the master
branch. This also works for specific tags:
Here the query parameter at=refs/tags/testtag1
refers to the tag (commit) testtag1
.
But because of the nature of our implementation, we would like to refer directly to a commit SHA-1 hash via the Bitbucket REST API. Is this possible?
Obviously, one ugly workaround would be to just add a tag to every commit. But this could bloat the repository and it also feels like an unnecessary hack.
With the help of this SO question, I found one of the answers which tipped me off to the correct syntax. Use this:
<URL>?at=commit_hash
For example:
Here is a table of three main endpoint types with the Bitbucket REST API:
query parameter | role
---------------------------------------------
refs/heads/master | specify master branch
refs/tags/someTag | specify 'someTag' tag
at=bed2dda5 | specify commit #bed2dda5