我找不到关于如何以新的位桶格式访问旧提交的源代码的文档。这还有可能吗?
当前回答
步骤1
步骤2
步骤3
步骤4
最后一步
其他回答
步骤1
步骤2
步骤3
步骤4
最后一步
搜索了很长时间,终于,我找到了怎么做:)
请看这张说明步骤的图片。
我知道这已经太迟了,但是有了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
}
其中> 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
将此添加到任何url的末尾:?at=102beada4f1(使用相关的提交SHA)。
注意:每次加载新页面时,参数都会被“忘记”,所以请准备好ctrl + c和ctrl + v。
令人惊讶的是BitBucket/Stash在UI中没有“浏览文件”按钮,就像GitHub有:
叹息。
您可以通过追加来查看特定提交之前的文件源 ?until=< shaf -commit>在URL中(在文件名之后)。