推送和拉取#
¥Push and pull
如果你的 n8n 实例连接到 Git 仓库,你需要保持你的工作与 Git 同步。
¥If your n8n instance connects to a Git repository, you need to keep your work in sync with Git.
本文档假设你熟悉 Git 的概念和术语。有关 n8n 如何与 Git 协同工作的介绍,请参阅 Git 和 n8n。
¥This document assumes some familiarity with Git concepts and terminology. Refer to Git and n8n for an introduction to how n8n works with Git.
Recommendation: don't push and pull to the same n8n instance
You can push work from an instance to a branch, and pull to the same instance. n8n doesn't recommend this. To reduce the risk of merge conflicts and overwriting work, try to create a process where work goes in one direction: either to Git, or from Git, but not both.
获取其他人的工作#
¥Fetch other people's work
n8n roles control which users can pull (fetch) changes
你必须是实例所有者或实例管理员才能从 Git 拉取更改。
¥You must be an instance owner or instance admin to pull changes from git.
要从 Git 拉取代码,请在主菜单中选择“拉取
”。
¥To pull work from Git, select Pull {.off-glb} in the main menu.
n8n 可能会显示有关覆盖本地更改的警告。选择“拉取并覆盖”以使用 Git 中的内容覆盖你的本地工作。
¥n8n may display a warning about overriding local changes. Select Pull and override to override your local work with the content in Git.
当更改包含新的变量或凭据存根时,n8n 会通知你需要在使用这些项之前填充其值。
¥When the changes include new variable or credential stubs, n8n notifies you that you need to populate the values for the items before using them.
How deleted resources are handled
当工作流、凭据、变量和标签从存储库中删除时,这些资源的本地版本不会自动删除。当你拉取存储库更改时,n8n 会通知你任何过时的资源,并询问你是否要删除它们。
¥When workflows, credentials, variables, and tags are deleted from the repository, your local versions of these resources aren't deleted automatically. Instead, when you pull repository changes, n8n notifies you about any outdated resources and asks if you'd like to delete them.
工作流和凭据所有者可能会在拉取时更改#
¥Workflow and credential owner may change on pull
从 Git 拉取代码到 n8n 实例时,n8n 会尝试将工作流和凭据分配给匹配的用户或项目。
¥When you pull from Git to an n8n instance, n8n tries to assign workflows and credentials to a matching user or project.
如果原始所有者是用户:
¥If the original owner is a user:
如果两个实例中都存在同一所有者(电子邮件地址匹配),则所有者保持不变。如果原始所有者不在新实例上,n8n 会将执行拉取操作的用户设置为工作流所有者。
¥If the same owner is available on both instances (matching email), the owner remains the same. If the original owner isn't on the new instance, n8n sets the user performing the pull as the workflow owner.
如果原始所有者是 project:
¥If the original owner is a project:
n8n 力求将原始项目名称与新实例中的项目名称匹配。如果不存在匹配的项目,n8n 将创建一个新项目,并将当前用户指定为项目所有者,并将工作流和凭据导入到该项目中。
¥n8n tries to match the original project name to a project name on the new instance. If no matching project exists, n8n creates a new project with the name, assigns the current user as project owner, and imports the workflows and credentials to the project.
拉取操作可能会导致短暂的服务中断#
¥Pulling may cause brief service interruption
如果你将更改拉取到活动工作流,n8n 会在拉取期间将工作流设置为非活动状态,然后在拉取期间重新激活它。这可能会导致工作流中断几秒钟。
¥If you pull changes to an active workflow, n8n sets the workflow to inactive while pulling, then reactivates it. This may result in a few seconds of downtime for the workflow.
将你的工作发送到 Git#
¥Send your work to Git
n8n roles control which users can push changes
你必须是实例所有者、实例管理员或项目管理员才能将更改推送到 Git。
¥You must be an instance owner, instance admin, or project admin to push changes to git.
To push work to Git:
-
Select Push
in the main menu. -
In the Commit and push changes modal, select which workflows you want to push. You can filter by status (new, modified, deleted) and search for workflows. n8n automatically pushes tags, and variable and credential stubs.
- Enter a commit message. This should be a one sentence description of the changes you're making.
- Select Commit and Push. n8n sends the work to Git, and displays a success message on completion.
提交了什么?#
¥What gets committed
n8n 将以下内容提交到 Git:
¥n8n commits the following to Git:
- 工作流,包括其标签和工作流所有者的电子邮件地址。你可以选择要推送的工作流。
¥Workflows, including their tags and the email address of the workflow owner. You can choose which workflows to push.
- 凭据存根 - ID、名称和类型。仅当字段类型为 expressions 时,才会包含其他字段。你可以选择要推送的凭据。
¥Credential stubs - ID, name and type. Any other fields are included only if they are expressions. You can choose which credentials to push.
- 变量存根(ID 和名称)
¥Variable stubs (ID and name)
-
Projects
-
文件夹
¥Folders
合并行为和冲突#
¥Merge behaviors and conflicts
n8n 的源代码控制实现带有预设的倾向性。它会自动解决凭据和变量的合并冲突。n8n 无法检测工作流中的冲突。
¥n8n's implementation of source control is opinionated. It resolves merge conflicts for credentials and variables automatically. n8n can't detect conflicts on workflows.
工作流#
¥Workflows
在推送或拉取工作流时,你必须明确告知 n8n 如何处理。Git 仓库作为权威数据源。
¥You have to explicitly tell n8n what to do about workflows when pushing or pulling. The Git repository acts as the source of truth.
拉取代码时,你可能会收到警告,提示你的本地工作流副本与 Git 中的版本不同。如果你接受警告,你的本地副本将被覆盖。拉取数据时,请注意不要丢失相关更改。
¥When pulling, you might get warned that your local copy of a workflow differs from Git, and if you accept, your local copy would be overridden. Be careful not to lose relevant changes when pulling.
推送代码时,本地工作流会覆盖 Git 中的内容,因此请确保你使用的是最新版本,否则可能会覆盖最近的更改。
¥When you push, your local workflow will override what's in Git, so make sure that you have the most up to date version or you risk overriding recent changes.
为了避免上述问题,你应该在完成工作后立即将更改推送到工作流。现在可以安全地拉取数据了。
¥To prevent the issue described above, you should immediately push your changes to a workflow once you finish working on it. Then it's safe to pull.
避免数据丢失:
¥To avoid losing data:
- 设计你的源代码控制设置,使工作流单向流动。例如,在开发实例上进行编辑,推送到 Git,然后拉取到生产环境。请勿在生产实例上进行编辑并推送。
¥Design your source control setup so that workflows flow in one direction. For example, make edits on a development instance, push to Git, then pull to production. Don't make edits on the production instance and push them.
- 请勿推送所有工作流。选择所需的节点。
¥Don't push all workflows. Select the ones you need.
- 谨慎手动编辑 Git 仓库中的文件。
¥Be cautious about manually editing files in the Git repository.
凭据、变量和工作流标签#
¥Credentials, variables and workflow tags
凭据和变量不会出现合并问题,因为 n8n 会选择保留哪个版本。
¥Credentials and variables can't have merge issues, as n8n chooses the version to keep.
拉取时:
¥On pull:
- 如果标签、变量或凭据不存在,n8n 将创建它。
¥If the tag, variable or credential doesn't exist, n8n creates it.
- 如果标签、变量或凭据已存在,n8n 不会更新它,除非:
¥If the tag, variable or credential already exists, n8n doesn't update it, unless:
-
你可以使用 API 或外部方式设置变量的值。新值将覆盖任何现有值。
¥You set the value of a variable using the API or externally. The new value overwrites any existing value.
-
凭据名称已更改。n8n 使用 Git 中的版本。
¥The credential name has changed. n8n uses the version in Git.
-
标签名称已更改。n8n 更新标签名称。重命名标签时务必谨慎,因为标签名称是唯一的,这可能会导致拉取过程中出现数据库唯一性问题。
¥The name of a tag has changed. n8n updates the tag name. Be careful when renaming tags as tag names are unique and this could cause database issues when it comes to uniqueness during the pull process.
推送时:
¥On push:
- n8n 覆盖所有变量和标签文件。
¥n8n overwrites the entire variables and tags files.
- 如果凭证已存在,n8n 会用更改覆盖它,但不会在拉取数据时将这些更改应用到现有凭证。
¥If a credential already exists, n8n overwrites it with the changes, but doesn't apply these changes to existing credentials on pull.
Manage credentials with an external secrets vault
如果你需要在不同的 n8n 环境中使用不同的凭据,请使用 外部密钥。
¥If you need different credentials on different n8n environments, use external secrets.

