【发布时间】:2013-01-09 19:16:02
【问题描述】:
我无法弄清楚或找到有关如何以新的 Bit Bucket 格式访问旧提交源的文档。这还有可能吗?
【问题讨论】:
-
什么新格式?你使用 Mercurial 还是 Git?只需使用 Mercurial 或 Git 客户端更新到旧版本。
标签: bitbucket
我无法弄清楚或找到有关如何以新的 Bit Bucket 格式访问旧提交源的文档。这还有可能吗?
【问题讨论】:
标签: bitbucket
我了解到您想通过 BitBucket Web 界面下载旧版本,而不使用 Mercurial/Git 客户端。
检查此related question。在 cmets 上,有人说没有办法做到这一点。幸运的是,这并不完全正确。
通过在 BitBucket 项目页面上导航,我没有找到下载任意版本的链接。有下载特定标签的链接,格式为:
https://bitbucket.org/owner/repository/get/v0.1.2.tar.gz
但是通过稍微调整一下上面的 url,通过提交哈希更改标签名称,例如:
https://bitbucket.org/owner/repository/get/A0B1C2D.tar.gz
您实际上可以下载特定版本。
正如Rakka Rage 在评论中提到的,将.tar.gz 替换为.zip 也可以。
【讨论】:
bitbucket.org。也许您的意思是 bitbucket.org URL 将为此目的而被弃用?是这样吗?
bitbucket.org
我试图弄清楚是否可以像在 GitHub 上一样浏览早期提交的代码,它把我带到了这里。我使用了我在这里找到的信息,在摆弄了 url 之后,我实际上也找到了一种浏览旧提交代码的方法。
当您浏览代码时,URL 类似于:
https://bitbucket.org/user/repo/src/
并在末尾添加一个提交哈希,如下所示:
https://bitbucket.org/user/repo/src/a0328cb
您可以在提交时浏览代码。我不明白为什么没有直接选择提交的下拉框,该功能已经存在。奇怪。
【讨论】:
https://bitbucket.org/lyro/evil/src/8cbfd51,但是如果你输入hg clone https://bitbucket.org/lyro/evil/src/8cbfd51,你会得到一些随机的修订,也许是最新的。
hg clone -r8cbfd51 https://bitbucket.org/lyro/evil/src/
https://bitbucket.org/user/project/commits/0000000000000000000000000000000000000000?at=master。现在,只需将 url 中的 commits 更改为 src,您就可以在此提交中浏览完整源代码!
以防万一有人在我的船上,而这些答案都没有完全奏效,这就是我所做的。
也许我们内部的 Bitbucket 服务器的设置与大多数服务器略有不同,但这里是我通常用于查看 master 分支中文件的 URL:
https://<BITBUCKET_URL>/projects/<PROJECT_GROUP>/repos/<REPO_NAME>/browse
如果我从下拉菜单中选择与 master 不同的分支,我会得到:
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>
现在我可以浏览提交时的整个 repo。
【讨论】:
为了记录,你也可以这样玩弄 URL:
浏览最新的源代码时,您会看到类似:
https://bitbucket.org/my/repo/src/latestcommithash/my.file?at=master
只需更改提交哈希并删除 GET 参数:
https://bitbucket.org/my/repo/src/wantedcommithash/my.file
在上面 +1 @Hein A. Grønnestad:一切正常,真的想知道为什么 GUI 中没有任何东西可以使用它。
【讨论】:
您可以通过追加查看文件的源直到特定的提交
URL 中的?until=<sha-of-commit>(在文件名之后)。
【讨论】:
最简单的方法是单击该提交并向该提交添加标签。 I have included the tag 'last_commit' with this commit
比在位桶的侧面导航左角去下载。 Click on download in the left side
【讨论】:
我知道为时已晚,但使用 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。
【讨论】:
您可以在您的 BitBucket 网站上查看它
正如Atlassian community site 中所解释的那样,转到Source 页面(可从左侧菜单中获得)并将您的提交ID 放入url 的at= 查询参数中就足够了。因此,例如,url 将以?at=bacf2ad3095 结尾。
【讨论】:
找了半天,终于找到了方法:)
请查看说明步骤的图片。
【讨论】:
以 Atlassian Bitbucket v6.10 为例
https://<bitbucket.myserver.it>/projects/<myproject>/repos/<myrepo>/browse?at=<full-commit-hash>
【讨论】: