How to access full source of old commit in BitBucket?
Asked Answered
Z

13

264

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?

Zaremski answered 25/1, 2013 at 18:44 Comment(1)
What new format? Are you using Mercurial or Git? Just use Mercurial or Git clients to update to an old version.Logy
S
383

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.

Scantling answered 5/6, 2013 at 3:19 Comment(6)
Can I use the link above in the Android Studio terminal to clone a commit? If so, could you provide the basic terminal code?Crossbill
I wish they would show this on their website so it was obvious.Ringside
Why is it not relevant? I just tested it again (2018-08-06) and it still works. Maybe its an issue with "in house" BitBucket servers? I tested this on the bitbucket.org server.Scantling
should be api.bitbucket.org nowErnaldus
@AlexanderMills, I just tested and it works with just bitbucket.org as above. Maybe you mean that the bitbucket.org URL will be deprecated for this purpose? Is that it?Scantling
Can confirm it still works with just bitbucket.orgOakley
I
220

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.

Iluminadailwain answered 13/8, 2013 at 11:51 Comment(4)
This is exactly what I needed. A direct link from Bitbucket's site to this URL is sorely missing.Carefree
Alas, this doesn't work. Or rather work, but partially. E.g. you can browse https://bitbucket.org/lyro/evil/src/8cbfd51 but if you enter hg clone https://bitbucket.org/lyro/evil/src/8cbfd51, you'd get some random revision, perhaps the latest.Polyphonic
Found a workaround, it's hg clone -r8cbfd51 https://bitbucket.org/lyro/evil/src/Polyphonic
For those who don't like to copy+paste: browse to a certain commit, the url will be something like https://bitbucket.org/user/project/commits/0000000000000000000000000000000000000000?at=master. Now, just change commits in the url to src and you are browsing the full source at this commit!Yttria
E
208

Step 1

Step 1


Step 2

Step 2


Step 3

Step 3


Step 4

Step 4


Final Step

Final Step

Eternize answered 10/2, 2015 at 4:30 Comment(6)
@ManojG Here's one from me. So apparently there is a way to get to the whole tree at a certain commit, albeit in a rather confusing way.Acropolis
LOVE THIS ANSWER. Note: you can also go to the file and use the drop down. THANK YOU!Canescent
More amazing than this answer is the fact that we can't do it on a button click... some things are really amazing....Ciliolate
this step did not solved for me, what gave results: the answer from @mattdlockyer, select a file, click on the drop down, select a older commit and then return to the repo base link like the last image from oscar postCribbing
All this works but when download it, its always the latest commit. Am i doing it wrong or it is that way?Babbittry
Step 3 is an icon now, and the Download button in step 4 and "final" is hidden behind the "..." nowCabinda
H
43

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.

Huarache answered 26/10, 2016 at 17:44 Comment(2)
This answer is the only one that actually works. The more popular ones seem to refer to older versions of BitbucketEgoism
Genius! Exactly what I was after, this is brilliantHeraclitean
F
10

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

Follow answered 6/3, 2017 at 17:9 Comment(1)
This was easily the simplest way to go. For those who have been unable to get tags issues, click on a specific commit and at the top right you will see view source, the branch, the commit, and tags. Add your tag there, then go to download it.Erective
B
8

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.

Beane answered 28/1, 2014 at 14:28 Comment(0)
L
6

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.

Lattermost answered 13/4, 2022 at 3:53 Comment(0)
T
3
  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
Themselves answered 6/6, 2019 at 12:35 Comment(0)
I
3

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.

Inandin answered 18/8, 2021 at 19:42 Comment(0)
E
2

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).

Enwomb answered 7/2, 2018 at 15:52 Comment(0)
S
1

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

Spoke answered 20/11, 2018 at 23:39 Comment(0)
S
1

Go to the commit you want... enter image description here

and the click on View Source enter image description here

Salyer answered 9/5, 2023 at 18:41 Comment(0)
D
0

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

Donetta answered 21/8, 2020 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.