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


当前回答

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

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

其他回答

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

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

我知道这已经太迟了,但是有了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

步骤1


步骤2


步骤3


步骤4


最后一步

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

也许我们内部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>

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

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

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