Skip to main content
Version: 10.x

Git 分支锁定文件

Git 分支锁定文件允许你完全避免锁定文件合并冲突并稍后解决。

¥Git branch lockfiles allows you to totally avoid lockfile merge conflicts and solve it later.

使用 git 分支锁定文件

¥Use git branch lockfiles

你可以通过配置 pnpm-workspace.yaml 文件来打开此功能。

¥You can turn on this feature by configuring the pnpm-workspace.yaml file.

gitBranchLockfile: true

通过这样做,将根据当前分支名称生成锁定文件名称。

¥By doing this, lockfile name will be generated based on the current branch name.

例如,当前分支名称为 feature-1。然后,生成的锁定文件名称将为 pnpm-lock.feature-1.yaml。你可以将其提交到 Git,并稍后合并所有 git 分支锁定文件。

¥For instance, the current branch name is feature-1. Then, the generated lockfile name will be pnpm-lock.feature-1.yaml. You can commit it to the Git, and merge all git branch lockfiles later.

- <project_folder>
|- pnpm-lock.yaml
|- pnpm-lock.feature-1.yaml
|- pnpm-lock.<branch_name>.yaml
注意

feature/1 的特殊之处在于 / 会自动转换为 !,因此对应的锁定文件名称将是 pnpm-lock.feature!1.yaml

¥feature/1 is special in that the / is automatically converted to !, so the corresponding lockfile name would be pnpm-lock.feature!1.yaml.

合并 git 分支锁定文件

¥Merge git branch lockfiles

pnpm install --merge-git-branch-lockfiles

要合并所有 git 分支锁定文件,只需指定 --merge-git-branch-lockfilespnpm install 命令。

¥To merge all git branch lockfiles, just specify --merge-git-branch-lockfiles to pnpm install command.

之后所有 git 分支的 lockfiles 都会合并成一个 pnpm-lock.yaml

¥After that, all git branch lockfiles will be merged into one pnpm-lock.yaml

分支匹配

¥Branch Matching

pnpm 允许你通过匹配当前分支名称来指定 --merge-git-branch-lockfiles

¥pnpm allows you to specify --merge-git-branch-lockfiles by matching the current branch name.

例如,通过在 pnpm-workspace.yaml 文件中进行以下设置,pnpm installmain 分支中运行且分支名称以 release 开头时,将合并所有 git 分支锁定文件。

¥For instance, by the following setting in pnpm-workspace.yaml file, pnpm install will merge all git branch lockfiles when running in the main branch and the branch name starts with release.

mergeGitBranchLockfilesBranchPattern:
- main
- release*