如何在BitBucket中访问旧提交的完整源代码?

我找不到关于如何以新的位桶格式访问旧提交的源代码的文档。这还有可能吗?

120061 次浏览

我知道你想通过BitBucket web界面下载一个旧版本,而不使用Mercurial/Git客户端。

检查这个相关的问题。在评论中,有人说没有办法做到这一点。幸运的是,这并不完全正确。

通过浏览BitBucket项目页面,我没有找到下载任意版本的链接。这里有下载特定标签的链接,格式为:

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

但是通过稍微调整上面的url,通过提交散列更改标签名,比如:

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

你可以下载一个特定的版本。

正如Rakka愤怒在注释中提到的,用.zip替换.tar.gz也可以。

我试图弄清楚是否有可能像你在GitHub上一样浏览之前提交的代码,它把我带到了这里。我使用了我在这里找到的信息,在摆弄了url之后,我实际上也找到了一种浏览旧提交代码的方法。

当你浏览你的代码时,URL是这样的:

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

通过在最后添加一个commit散列,就像这样:

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

您可以在提交时浏览代码。我不明白为什么没有直接选择提交的下拉框,这个功能已经存在了。奇怪。

为了记录,你也可以这样摆弄url:

当你浏览最新的源代码时,你会看到如下内容: https://bitbucket.org/my/repo/src/latestcommithash/my.file?at=master < / p > 简单地改变提交哈希并删除GET参数: https://bitbucket.org/my/repo/src/wantedcommithash/my.file < / p >

@Hein A. Grønnestad上面:它都在工作,真的很好奇为什么GUI中没有任何东西可以使用它。

步骤1

Step 1 .


步骤2

Step 2 .


步骤3

Step 3 .


步骤4

Step 4 .


最后一步

Final Step .

以防有人和我一样,这些答案都不正确,下面是我做的。

也许我们内部Bitbucket服务器的设置与大多数服务器有点不同,但这是我通常去查看主分支中的文件的URL:

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

如果我从下拉菜单中选择不同的分支,我会得到这个:

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

所以我试着这么做,结果成功了:

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

现在我可以浏览整个回购,因为它是在提交时。

几年前的回答很好。现在Bitbucket让它变得更容易了。

标记您想要下载的Commit(如Rudy Matela的回答所述)。

然后转到下载,点击“标签”标签,你会得到多个下载选项。

Tag Downloads

你可以通过追加来查看文件的源代码,直到特定的提交 在URL中?until=<sha-of-commit>(在文件名之后)

我知道这已经太迟了,但是有了API 2.0你就可以做到

从命令行输入:

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

或者在PHP中使用:

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

然后你有你的文件的历史记录(从最近的提交到最古老的提交):

{
"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
}

values > links > self提供了历史记录中当前时刻的文件,您可以使用curl <link>file_get_contents(<link>)检索它。

最终,在命令行中,你可以使用:

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

在php中,只需在数组$data上做一个foreach循环。

注意:如果<path_file>/,你必须在%2F中转换它。

在这里查看文档:https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/filehistory/%7Bnode%7D/%7Bpath%7D

    最简单的方法是单击该提交,并为该提交添加一个标签。 李我在这个提交中包含了标签'last_commit' < / p > < / >
  1. 而不是去下载在侧面导航在位桶的左上角。 李点击左边的下载 < / p > < / >

  2. 现在点击导航栏中的标签,从UI下载zip。 李找到您的标签并下载压缩包 < / >

搜索了很长时间,终于,我找到了怎么做:)

请看这张说明步骤的图片。 enter image description here

你可以在你的比特桶网站上查看

正如Atlassian社区网站中所解释的那样,转到Source页面(从左侧菜单中可用)并将你的提交id放在url的at=查询参数中就足够了。例如,url将以?at=bacf2ad3095结尾。

在我的情况下,Atlassian Bitbucket v6.10

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

将此添加到任何url的末尾:?at=102beada4f1(使用相关的提交SHA)。

注意:每次加载新页面时,参数都会被“忘记”,所以准备好ctrl + cctrl + v

BitBucket/Stash在UI中没有“浏览文件”按钮的< >强惊人的< / >强,就像GitHub有:

enter image description here

叹息。