Skip to content

Commit 17b1a57

Browse files
nowgnuesLeeyomybaby
authored andcommitted
docs(FR-2866): add pnpm-lock.yaml conflict resolution rule
Document the project convention for resolving pnpm-lock.yaml conflicts: always take main's version (via `git restore --source=main` or context- aware `git checkout --theirs`/`--ours`) and re-run `pnpm install` to let pnpm reconcile any new deps from the branch's package.json. This is the natural follow-up policy now that gitBranchLockfile is disabled and pnpm-lock.yaml is the single shared lockfile across all branches.
1 parent fb6f884 commit 17b1a57

1 file changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
description: When resolving pnpm-lock.yaml merge/rebase conflicts, always take main's version and re-run pnpm install instead of hand-merging
3+
---
4+
5+
# pnpm-lock.yaml Conflict Resolution Rule
6+
7+
When `pnpm-lock.yaml` conflicts during a merge, rebase, `gt sync`, or `gt restack`, **always take the main branch's version** rather than hand-merging the lockfile. Then run `pnpm install` to let pnpm reconcile any new dependencies from your branch's `package.json` / `pnpm-workspace.yaml`.
8+
9+
## Why
10+
11+
`pnpm-lock.yaml` is a large, auto-generated artifact. It is effectively a deterministic function of:
12+
13+
- `package.json` (in each workspace)
14+
- `pnpm-workspace.yaml` (catalog, overrides, patched dependencies, minimum release age policy)
15+
- pnpm's resolver
16+
17+
Hand-merging two versions of this file is error-prone — humans regularly miss transitive dependency mismatches, integrity hashes, or peer dependency notes, producing a lockfile that parses but doesn't correspond to a valid resolution state. CI then fails on `pnpm install --frozen-lockfile`, often in ways that point at the wrong root cause.
18+
19+
Since FR-2866 disabled `gitBranchLockfile`, every branch writes to the same canonical `pnpm-lock.yaml`. The cleanest resolution path is: take main's lockfile, then let pnpm re-resolve any new deps your branch added. pnpm will deterministically rewrite the file to match the post-merge `package.json` state — you don't lose your branch's dep changes, they're just re-derived.
20+
21+
## Pattern
22+
23+
### ✅ Recommended — `git restore --source=main` (context-independent)
24+
25+
```bash
26+
# Works the same in merge, rebase, gt sync, gt restack
27+
git restore --source=main pnpm-lock.yaml
28+
pnpm install
29+
git add pnpm-lock.yaml
30+
# then continue: git rebase --continue / gt continue / git commit
31+
```
32+
33+
`--source=main` explicitly names the source, so the command behaves identically whether you're in a merge or a rebase. Memorize this one form.
34+
35+
### ✅ Also correct — `git checkout --theirs` (during `git merge`)
36+
37+
```bash
38+
# After: git merge main → conflict in pnpm-lock.yaml
39+
git checkout --theirs pnpm-lock.yaml
40+
pnpm install
41+
git add pnpm-lock.yaml
42+
git commit
43+
```
44+
45+
In a **merge**, `--theirs` = the branch being merged in (main).
46+
47+
### ⚠️ Correct but reversed semantics — `git checkout --ours` (during rebase / `gt sync` / `gt restack`)
48+
49+
```bash
50+
# After: gt sync, gt restack, or git rebase main → conflict in pnpm-lock.yaml
51+
git checkout --ours pnpm-lock.yaml
52+
pnpm install
53+
git add pnpm-lock.yaml
54+
git rebase --continue # or: gt continue
55+
```
56+
57+
In a **rebase**, `--ours` and `--theirs` are swapped relative to merge: `--ours` = the base you're rebasing onto (main), `--theirs` = the commit being replayed (your branch). This is a well-known Git footgun. If you're unsure which context you're in, fall back to `git restore --source=main pnpm-lock.yaml` from the recommended pattern.
58+
59+
### ❌ Wrong — hand-merging the conflict markers
60+
61+
```yaml
62+
# DO NOT do this
63+
<<<<<<< HEAD
64+
'@some/pkg':
65+
version: 1.0.0
66+
=======
67+
'@some/pkg':
68+
version: 1.1.0
69+
>>>>>>> main
70+
```
71+
72+
Lockfile conflict regions can span hundreds of lines and reference interconnected `packages:`, `snapshots:`, and `importers:` sections. Hand-editing them produces lockfiles that pass parsing but fail `pnpm install --frozen-lockfile` in CI.
73+
74+
### ❌ Wrong — taking main's lockfile and skipping `pnpm install`
75+
76+
```bash
77+
git restore --source=main pnpm-lock.yaml
78+
git add pnpm-lock.yaml
79+
git commit # ← problem: if your branch added new deps to package.json,
80+
# they aren't in main's lockfile yet, so CI will fail on
81+
# pnpm install --frozen-lockfile.
82+
```
83+
84+
Always run `pnpm install` after restoring. pnpm will re-resolve any new deps your branch introduced and write a coherent lockfile.
85+
86+
## Rules
87+
88+
1. **Default**: `git restore --source=main pnpm-lock.yaml` — same command for merge and rebase.
89+
2. **Always follow up with `pnpm install`** so pnpm reconciles any new deps from your branch's `package.json` / `pnpm-workspace.yaml`.
90+
3. **Never hand-merge `pnpm-lock.yaml`** — the file is auto-generated; let the tool that owns it (pnpm) regenerate it.
91+
4. **Mind the rebase / merge swap** when using `--ours` / `--theirs`. In rebase, `--ours` is main; in merge, `--theirs` is main. When in doubt, use `--source=main`.
92+
5. **Same rule applies during `gt sync` and `gt restack`** — both use rebase semantics under the hood. Resolve with `git restore --source=main pnpm-lock.yaml`, run `pnpm install`, then `gt continue`.
93+
6. **Don't escalate routine lockfile conflicts** — they almost always resolve via this recipe. Escalate only if `pnpm install` itself fails after taking main's lockfile (which typically points at a real `package.json` / `pnpm-workspace.yaml` problem, not a lockfile problem).
94+
95+
## Related
96+
97+
- `pnpm-workspace.yaml` — the canonical source of truth for catalog, overrides, patched dependencies, and the `minimumReleaseAge` policy.
98+
- FR-2866 (PR #7359) — disabled `gitBranchLockfile`, making `pnpm-lock.yaml` the single shared lockfile across all branches.
99+
- pnpm docs on lockfile conflicts: <https://pnpm.io/git#dealing-with-merge-conflicts>

0 commit comments

Comments
 (0)