将笔记本与 Git 仓库同步¶
To use version control with your Snowflake Notebooks, you can sync your notebook development with a branch in a Git repository.
You must have already set up your Snowflake account to be connected to a Git repository and have created a branch in that repository to use for your notebook development. See Setting up Snowflake to use Git.
从 Git 存储库中的文件创建笔记本¶
Note
The file must be an .ipynb formatted file and it must use notebook format (nbformat) 4.0 or higher.
要从 Git 存储库中的文件创建 Snowflake 笔记本,请执行以下操作:
- Sign in to Snowsight.
- In the navigation menu, select Projects » Notebooks.
- Next to + Notebook, open the drop-down menu and select Create from repository.
- For File location in repository, select the repository and branch in the repository that contain the notebook file, then select
the specific
.ipynbfile. For details on connecting Snowflake to your Git repository, see Setting up Snowflake to use Git. - For Notebook location, select a database and schema to contain the notebook. These cannot be changed after you create the notebook.
- For Notebook warehouse, select a warehouse.
- Select Create to create a Snowflake Notebook from the
.ipynbfile in your Git repository.
将现有笔记本与 Git 存储库连接¶
要将现有的 Snowflake 笔记本连接到 Git 存储库,请执行以下操作:
Note
您必须至少使用具有以下权限的角色:
- 对 Git 存储库的 OWNERSHIP 或 READ 权限。
- 对包含 Git 存储库的架构的 USAGE 权限。
To learn how to connect to your Git repository, see Setting up Snowflake to use Git.
For more details, see Access control requirements.
- Sign in to Snowsight.
- In the navigation menu, select Projects » Notebooks, and then open or create a notebook.
- In the Files tab, next to the database object explorer, select Connect Git Repository.
- For File location in repository, select the repository and branch in the repository with which you want to sync the notebook.
- Select Select Folder.
- When you are prompted to commit and push your notebook to the Git repository, complete the Push to Git steps outlined in 将更改推送到 Git 存储库中的分支.
当笔记本成功推送到 Git 存储库后,系统将在 Git 存储库分支中的选定位置为笔记本创建一个新文件夹,并且该位置的所有文件和文件夹都将同步回笔记本。您可以选择分支名称并在 Snowflake 或 Git 中打开存储库详细信息。
将更改推送到 Git 存储库中的分支¶
如果 Snowflake 笔记本连接到 Git 存储库中的分支,则在对笔记本进行更改后,您可以将更改推送到该分支。
You must use a role with the OWNERSHIP or WRITE privilege on the Git repository to push your changes. For more details, see Access control requirements.
-
Sign in to Snowsight.
-
In the navigation menu, select Projects » Notebooks, and then open a notebook.
-
对笔记本进行任何相关更改。
-
Select Push to Git.
-
In the Push to Git dialog that appears, you can review the username and email address that are used to commit the changes to the specified branch and repository. If you need to update the username and email address, expand the Credentials section and update the Author name and Author email.
-
For Commit message, enter a message to include with your commit.
-
Expand the Credentials section to configure credentials. Enter your personal access token for the Git repository in the Personal access token field. This access token comes from the remote Git provider, such as GitHub.
- 需要此令牌才能向 Git 存储库进行身份验证。
- 此令牌必须具有对存储库内容的读写权限,才能使提交生效。
- 一旦输入,即会保存此令牌供日后提交。您可以在日后的任何提交期间更新它。
-
Select Push.
确认消息表明更改已成功推送到分支。
将笔记本与 Git 存储库中的远程分支同步¶
将笔记本连接到 Git 存储库中的分支后,您可以将远程分支中的所有更改与 Snowflake 笔记本同步。
- Sign in to Snowsight.
- In the navigation menu, select Projects » Notebooks, and then open or create a notebook.
- In the database object explorer, in the Files tab, select Pull.
Snowflake 会提取远程存储库分支上存在的所有更改,并将笔记本内容与这些更改合并。
合并冲突
Snowflake 会尝试解决同步期间发生的合并冲突。如果存在 Snowflake 无法解决的合并冲突,您将收到一条消息,要求您放弃更改或将其提交到新分支。当它们提交到新分支时,使用 Git 提供商将更改从新分支手动合并到原始分支。然后,您应该将最新的更新拉入 Snowflake 笔记本中。