How to access full source of old commit in BitBucket?

Bitbucket

Bitbucket Problem Overview


I can't figure out or find the documentation on how to access the source of an old commit in the new Bit Bucket format. Is this even possible anymore?

Bitbucket Solutions


Solution 1 - Bitbucket

I understand you want to download an older version via the BitBucket web interface without using a Mercurial/Git client.

Check this related question. On the comments, someone says that there is no way to do that. Fortunately, that's not entirely true.

By navigating on BitBucket project pages, I found no link to download an arbitrary version. There are links to download specific tags, in the format:

https://bitbucket.org/owner/repository/get/v0.1.2.tar.gz

But by tweaking a bit the url above, changing the tag name by the commit hash, like:

https://bitbucket.org/owner/repository/get/A0B1C2D.tar.gz

You can actually download a specific version.

As mentioned by Rakka Rage in a comment, replacing .tar.gz by .zip works too.

Solution 2 - Bitbucket

I was trying to figure out if it's possible to browse the code of an earlier commit like you can on GitHub and it brought me here. I used the information I found here, and after fiddling around with the urls, I actually found a way to browse code of old commits as well.

When you're browsing your code the URL is something like:

https://bitbucket.org/user/repo/src/

and by adding a commit hash at the end like this:

https://bitbucket.org/user/repo/src/a0328cb

You can browse the code at the point of that commit. I don't understand why there's no dropdown box for choosing a commit directly, the feature is already there. Strange.

Solution 3 - Bitbucket

Step 1

Step 1


Step 2

Step 2


Step 3

Step 3


Step 4

Step 4


Final Step

Final Step

Solution 4 - Bitbucket

Just in case anyone is in my boat where none of these answers worked exactly, here's what I did.

Perhaps our in house Bitbucket server is set up a little differently than most, but here's the URL that I'd normally go to just to view the files in the master branch:

https://<BITBUCKET_URL>/projects/<PROJECT_GROUP>/repos/<REPO_NAME>/browse

If I select a different branch than master from the drop down menu, I get this:

https://<BITBUCKET_URL>/projects/<PROJECT_GROUP>/repos/<REPO_NAME>/browse?at=refs%2Fheads%2F<BRANCH_NAME>

So I tried doing this and it worked:

https://<BITBUCKET_URL>/projects/<PROJECT_GROUP>/repos/<REPO_NAME>/browse?at=<COMMIT_ID>

Now I can browse the whole repo as it was at the time of that commit.

Solution 5 - Bitbucket

Great answers from a couple of years ago. Now Bitbucket has made it easier.

Tag the Commit you want to download (as mentioned in answer by Rudy Matela).

Then head over to Downloads and click the "Tags" tab and you'll get multiple options for download.

Tag Downloads

Solution 6 - Bitbucket

For the record, you can also toy around URLs this way :

When browsing the latest source, you have something like : https://bitbucket.org/my/repo/src/latestcommithash/my.file?at=master

Simply change the commit hash and remove the GET parameter : https://bitbucket.org/my/repo/src/wantedcommithash/my.file

Got to +1 @Hein A. Grønnestad above : it's all working, really wondering why there's nothing in the GUI to use it.

Solution 7 - Bitbucket

You can view the source of the file up to a particular commit by appending ?until=<sha-of-commit> in the URL (after the file name).

Solution 8 - Bitbucket

  1. The easiest way is to click on that commit and add a tag to that commit. I have included the tag 'last_commit' with this commit

  2. Than go to downloads in the left corner of the side nav in bit bucket. Click on download in the left side

  3. Now click on tags in the nav bar and download the zip from the UI. Find your tag and download the zip

Solution 9 - Bitbucket

You can view it on your BitBucket web site

As explained on Atlassian community site, it's enough to go to the Source page (available from left side menu) and put your commit id in the at= query parameter of the url. So, for example, the url will end with ?at=bacf2ad3095.

Solution 10 - Bitbucket

I know it's too late, but with API 2.0 you can do

from command line with:

curl https://api.bitbucket.org/2.0/repositories/<user>/<repo>/filehistory/<branch>/<path_file>

or in php with:

$data = json_decode(file_get_contents("https://api.bitbucket.org/2.0/repositories/<user>/<repo>/filehistory/<branch>/<path_file>", true));

then you have the history of your file (from the most recent commit to the oldest one):

{
"pagelen": 50,
"values": [
    {
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/src/<hash>/<path_file>"
        },
        "meta": {
          "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/src/<HEAD>/<path_file>?format=meta"
        },
        "history": {
          "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/filehistory/<HEAD>/<path_file>"
        }
      },
      "commit": {
        "hash": "<HEAD>",
        "type": "commit",
        "links": {
          "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/commit/<HEAD>"
          },
          "html": {
            "href": "https://bitbucket.org/<user>/<repo>/commits/<HEAD>"
          }
        }
      },
      "attributes": [],
      "path": "<path_file>",
      "type": "commit_file",
      "size": 31
    },
    {
      "links": {
        "self": {
          "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/src/<HEAD~1>/<path_file>"
        },
        "meta": {
          "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/src/<HEAD~1>/<path_file>?format=meta"
        },
        "history": {
          "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/filehistory/<HEAD~1>/<path_file>"
        }
      },
      "commit": {
        "hash": "<HEAD~1>",
        "type": "commit",
        "links": {
          "self": {
            "href": "https://api.bitbucket.org/2.0/repositories/<user>/<repo>/commit/<HEAD~1>"
          },
          "html": {
            "href": "https://bitbucket.org/<user>/<repo>/commits/<HEAD~1>"
          }
        }
      },
      "attributes": [],
      "path": "<path_file>",
      "type": "commit_file",
      "size": 20
    }
  ],
  "page": 1
}

where values > links > self provides the file at the moment in the history which you can retrieve it with curl <link> or file_get_contents(<link>).

Eventually, from the command line you can filter with:

 curl https://api.bitbucket.org/2.0/repositories/<user>/<repo>/filehistory/<branch>/<path_file>?fields=values.links.self

in php, just make a foreach loop on the array $data.

Note: if <path_file> has a / you have to convert it in %2F.

See the doc here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/filehistory/%7Bnode%7D/%7Bpath%7D

Solution 11 - Bitbucket

Search it for a long time, and finally, I found how to do it:)

Please check this image which illustrates steps. enter image description here

Solution 12 - Bitbucket

In my case with Atlassian Bitbucket v6.10

https://<bitbucket.myserver.it>/projects/<myproject>/repos/<myrepo>/browse?at=<full-commit-hash>

Solution 13 - Bitbucket

Add this to the end of any url: ?at=102beada4f1 (using the relevant commit SHA).

Note: the parameter is 'forgotten' with every new page load, so get ctrl + c and ctrl + v ready.

It's astonishing that BitBucket/Stash has no 'Browse files' button in the UI, like GitHub has:

enter image description here

Sigh.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSer PounceView Question on Stackoverflow
Solution 1 - BitbucketRudy MatelaView Answer on Stackoverflow
Solution 2 - BitbucketHein Andre GrønnestadView Answer on Stackoverflow
Solution 3 - BitbucketAskarView Answer on Stackoverflow
Solution 4 - BitbucketBrent212View Answer on Stackoverflow
Solution 5 - BitbucketLMSinghView Answer on Stackoverflow
Solution 6 - BitbucketneemzyView Answer on Stackoverflow
Solution 7 - BitbucketEugenView Answer on Stackoverflow
Solution 8 - Bitbucketshubham tripathiView Answer on Stackoverflow
Solution 9 - BitbucketJacek JView Answer on Stackoverflow
Solution 10 - BitbuckettormecView Answer on Stackoverflow
Solution 11 - BitbucketEdward XView Answer on Stackoverflow
Solution 12 - BitbucketEdoardo VignatiView Answer on Stackoverflow
Solution 13 - BitbucketstevecView Answer on Stackoverflow