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。
合并 git 分支锁定文件
🌐 Merge git branch lockfiles
pnpm install --merge-git-branch-lockfiles
要合并所有 git 分支的锁文件,只需指定 --merge-git-branch-lockfiles 到 pnpm install 命令。
🌐 To merge all git branch lockfiles, just specify --merge-git-branch-lockfiles to pnpm install command.
之后,所有 git 分支锁文件将合并为一个 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 install 在 main 分支运行且分支名称以 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*