Bitbucket 云版本控制 Bitbucket Cloud version control

本指南介绍了如何通过 UI 使用 Bitbucket 云为笔记本设置版本控制。This guide describes how to set up version control for notebooks using Bitbucket Cloud through the UI. 虽然本文档介绍的是如何通过 UI 设置 Bitbucket 云集成,但你也可以使用 Databricks CLI工作区 API 来导入和导出笔记本,并使用 Bitbucket 工具管理笔记本版本。Although this document describes how to set up Bitbucket Cloud integration through the UI, you can also use the Databricks CLI or Workspace API to import and export notebooks and manage the notebook versions using Bitbucket tools.

启用和禁用 Git 版本控制Enable and disable Git versioning

默认情况下会启用版本控制。By default version control is enabled. 若要切换此设置,请参阅管理 Git 中的笔记本版本控制功能To toggle this setting, see Manage the ability to version notebooks in Git. 如果禁用 Git 版本控制,则“用户设置”屏幕中的“Git 集成”选项卡将不可见 。If Git versioning is disabled, the Git Integration tab is not visible in the User Settings screen.

配置版本控制Configure version control

配置版本控制需要在版本控制提供程序中创建访问凭据,然后将这些凭据添加到 Azure Databricks。Configuring version control involves creating access credentials in your version control provider and adding those credentials to Azure Databricks.

获取应用密码Get an app password

  1. 转到 Bitbucket 云,创建允许访问存储库的应用密码。Go to Bitbucket Cloud and create an app password that allows access to your repositories. 请参阅 Bitbucket 云文档See the Bitbucket Cloud documentation.
  2. 记录密码。Record the password. 在下一步中,在 Azure Databricks 中输入此密码。You enter this password in Azure Databricks in the next step.

将你的应用密码和用户名保存到 Azure DatabricksSave your app password and username to Azure Databricks

  1. 单击屏幕右上方的用户图标 帐户图标,然后选择“用户设置”。Click the User icon Account Icon at the top right of your screen and select User Settings.

    帐户设置Account settings

  2. 单击“Git 集成”选项卡。Click the Git Integration tab.

  3. 如果你之前输入过凭据,请单击“更改令牌或应用密码”按钮。If you have previously entered credentials, click the Change token or app password button.

  4. 在 Git 提供程序下拉列表中,选择“Bitbucket 云”。In the Git provider drop-down, select Bitbucket Cloud.

    Bitbucket 云 GitHub 提供程序Bitbucket Cloud GitHub provider

  5. 将密码和用户名粘贴到相应的字段中,然后单击“保存”。Paste your password and username into the respective fields and click Save.

使用笔记本修订版Work with notebook revisions

可以在“历史记录”面板中使用笔记本修订版本。You work with notebook revisions in the History panel. 单击笔记本右上角的“修订历史记录”,以打开历史记录面板。Open the history panel by clicking Revision history at the top right of the notebook.

修订历史记录Revision history

备注

“历史记录”面板处于打开状态时,无法修改笔记本。You cannot modify a notebook while the History panel is open.

  1. 打开“历史记录”面板。Open the History panel. Git 状态栏显示“Git:未链接”。The Git status bar displays Git: Not linked.

    “历史记录”面板History panel

  2. 单击“Git:未链接”。Click Git: Not linked.

    此时会显示“Git 首选项”对话框。The Git Preferences dialog displays. 第一次打开笔记本时,“状态”为“未链接”,因为笔记本不在 Bitbucket 云中。The first time you open your notebook, the Status is Unlink , because the notebook is not in Bitbucket Cloud.

    Git 首选项Git preferences

  3. 在“状态”字段中,单击“链接”。In the Status field, click Link.

  4. 在“链接”字段中,粘贴 Bitbucket 云存储库的 URL。In the Link field, paste the URL of the Bitbucket Cloud repository.

  5. 单击“分支”下拉列表,选择一个分支。Click the Branch drop-down and select a branch.

  6. 在“Git 存储库中的路径”字段中,指定文件在存储库中的存储位置。In the Path in Git Repo field, specify where in the repository to store your file.

    Python 笔记本具有建议的默认文件扩展名 .pyPython notebooks have the suggested default file extension .py. 如果使用 .ipynb,则笔记本会以 iPython 笔记本格式保存。If you use .ipynb, your notebook will save in iPython notebook format. 如果文件已存在于 Bitbucket 云中,则可以直接复制并粘贴文件的 URL。If the file already exists on Bitbucket Cloud, you can directly copy and paste the URL of the file.

  7. 单击“保存”即可完成对笔记本的链接。Click Save to finish linking your notebook. 如果此文件之前不存在,则会显示一个提示,其中包含“将此文件保存到 Bitbucket 云存储库”选项。If this file did not previously exist, a prompt with the option Save this file to your Bitbucket Cloud repo displays.

  8. 键入一条消息,然后单击“保存”。Type a message and click Save.

将笔记本保存到 Bitbucket 云Save a notebook to Bitbucket Cloud

尽管对笔记本所做的更改会自动保存到 Azure Databricks 修订历史记录,但更改不会自动保存到 Bitbucket 云。While the changes that you make to your notebook are saved automatically to the Azure Databricks revision history, changes do not automatically persist to Bitbucket Cloud.

  1. 打开“历史记录”面板。Open the History panel.

    “历史记录”面板History panel

  2. 单击“立即保存”,将笔记本保存到 Bitbucket 云。Click Save Now to save your notebook to Bitbucket Cloud. 此时会显示“保存笔记本修订版本”对话框。The Save Notebook Revision dialog displays.

  3. 根据需要,输入一条消息以对更改进行说明。Optionally, enter a message to describe your change.

  4. 确保选中“另提交到 Git”。Make sure that Also commit to Git is selected.

    保存修订版本Save revision

  5. 单击“保存” 。Click Save.

将笔记本还原或更新为 Bitbucket 云中的版本Revert or update a notebook to a version from Bitbucket Cloud

链接笔记本后,每次重新打开“历史记录”面板时,Azure Databricks 都会将历史记录与 Git 同步。Once you link a notebook, Azure Databricks syncs your history with Git every time you re-open the History panel. 同步到 Git 的版本将提交哈希作为条目的一部分。Versions that sync to Git have commit hashes as part of the entry.

  1. 打开“历史记录”面板。Open the History panel.

    “历史记录”面板History panel

  2. 在“历史记录”面板中选择一个条目。Choose an entry in the History panel. Azure Databricks 会显示该版本。Azure Databricks displays that version.

  3. 单击“还原此版本”。Click Restore this version.

  4. 单击“确认”,以确认是否要还原该版本。Click Confirm to confirm that you want to restore that version.

  1. 打开“历史记录”面板。Open the History panel.

  2. Git 状态栏显示“Git: 已同步”。The Git status bar displays Git: Synced.

    Git 状态Git status

  3. 单击“Git: 已同步”。Click Git: Synced.

    Git 首选项Git preferences

  4. 在“Git 首选项”对话框中,单击“取消链接”。In the Git Preferences dialog, click Unlink.

  5. 单击“保存” 。Click Save.

  6. 单击“确认”,以确认是否要断开笔记本与版本控制的链接。Click Confirm to confirm that you want to unlink the notebook from version control.

创建拉取请求Create a pull request

  1. 打开“历史记录”面板。Open History panel.

  2. 单击 Git 状态栏以打开“Git 首选项”对话框。Click the Git status bar to open the Git Preferences dialog.

    Git 首选项Git preferences

  3. 单击“创建 PR”。Click Create PR. Bitbucket 云会打开到分支的拉取请求页。Bitbucket Cloud opens to a pull request page for the branch.

代码评审的最佳做法Best practice for code reviews

Azure Databricks 支持进行 Git 分支。Azure Databricks supports Git branching.

  • 可以将笔记本链接到你自己的分支,然后选择一个分支。You can link a notebook to your own fork and choose a branch.
  • 建议为每个笔记本使用单独的分支。We recommend using separate branches for each notebook.
  • 对更改满意后,可以点击“Git 首选项”对话框中的“创建 PR”链接,转到 Bitbucket 云的拉取请求页面。Once you are happy with your changes, you can use the Create PR link in the Git Preferences dialog to take you to Bitbucket Cloud’s pull request page.
  • 仅在不使用父存储库的默认分支时,才会显示“创建 PR”链接。The Create PR link displays only if you’re not working on the default branch of the parent repository.

Bitbucket 服务器Bitbucket Server

重要

不支持 Bitbucket 服务器集成。Bitbucket Server integration is not supported. 但是,可以使用工作区 API 在 Bitbucket 服务器中以编程方式创建笔记本并管理代码库。However, you can use the Workspace API to programmatically create notebooks and manage the code base in Bitbucket Server.

疑难解答Troubleshooting

如果收到与 Bitbucket 云历史记录同步相关的错误,请验证以下事项:If you receive errors related to Bitbucket Cloud history sync, verify the following:

  1. 你已初始化 Bitbucket 云中的存储库,该存储库不为空。You have initialized the repository on Bitbucket Cloud, and it isn’t empty. 试用你输入的 URL,验证它是否转发到你的 Bitbucket 云存储库。Try the URL that you entered and verify that it forwards to your Bitbucket Cloud repository.
  2. 你的应用密码处于活动状态,你的用户名正确。Your app password is active and your username is correct.
  3. 如果存储库是专用的,你应该会在存储库上获得读取和写入访问权限(通过 Bitbucket 云获得)。If the repository is private, you should have read and write access (through Bitbucket Cloud) on the repository.