|
| 1 | +# Restack |
| 2 | + |
| 3 | +Use when user asks to "restack", "resolve conflicts", "gt restack", or mentions restack conflicts. Guides through gt restack conflicts with intelligent diagnostics and resolution. (project) |
| 4 | + |
| 5 | +<critical> |
| 6 | +- ALWAYS check current state first (supports both: starting fresh or mid-conflict) |
| 7 | +- If already in conflict, skip running gt restack and go straight to resolution |
| 8 | +- Differentiate simple (lockfile-only) vs complex (multi-file) conflicts |
| 9 | +- Loop until restack completes successfully |
| 10 | +- Use AskUserQuestion for confirmations and choices |
| 11 | +</critical> |
| 12 | + |
| 13 | +## Workflow |
| 14 | + |
| 15 | +### 1. Detect Current State |
| 16 | + |
| 17 | +First, check if restack is already in progress: |
| 18 | + |
| 19 | +```bash |
| 20 | +git status |
| 21 | +``` |
| 22 | + |
| 23 | +**Check for**: |
| 24 | +- "rebase in progress" |
| 25 | +- "You are currently rebasing" |
| 26 | +- "Unmerged paths" |
| 27 | +- "both modified:" or other conflict indicators |
| 28 | + |
| 29 | +**Outcomes**: |
| 30 | +- Already in conflict (user ran `gt restack` manually) → Skip to step 3 (Gather Diagnostics) |
| 31 | +- Clean state → Proceed to step 2 (Run Restack) |
| 32 | + |
| 33 | +### 2. Run Restack (if not already in progress) |
| 34 | + |
| 35 | +```bash |
| 36 | +gt restack |
| 37 | +``` |
| 38 | + |
| 39 | +**Outcomes**: |
| 40 | +- Success → Acknowledge and exit |
| 41 | +- Conflicts → Proceed to step 3 |
| 42 | + |
| 43 | +### 3. Gather Diagnostics |
| 44 | + |
| 45 | +When conflicts are detected (either from step 1 or step 2), run: |
| 46 | + |
| 47 | +```bash |
| 48 | +# Check which files are conflicted |
| 49 | +git status |
| 50 | + |
| 51 | +# Show stack structure (where conflict occurred) |
| 52 | +gt log short |
| 53 | + |
| 54 | +# Check for broken lockfile warning |
| 55 | +pnpm install --dry-run 2>&1 | grep -i "broken\|duplicated\|ignoring" |
| 56 | + |
| 57 | +# For each conflicted file, show diff |
| 58 | +git diff <file> |
| 59 | +``` |
| 60 | + |
| 61 | +### 3. Explain Conflict Type |
| 62 | + |
| 63 | +**Simple conflict** (lockfile-only): |
| 64 | +- Only `pnpm-lock.yaml` in unmerged files |
| 65 | +- Explain: Lockfile is generated content, safe to regenerate |
| 66 | +- Propose: `pnpm install && gt add -A && gt continue` |
| 67 | + |
| 68 | +**Complex conflict** (multi-file): |
| 69 | +- Multiple files in unmerged files |
| 70 | +- Explain each file's conflict |
| 71 | +- Guide through resolution strategy |
| 72 | + |
| 73 | +### 4. Resolve Based on Type |
| 74 | + |
| 75 | +#### Simple Conflict Resolution |
| 76 | + |
| 77 | +Use AskUserQuestion: |
| 78 | +``` |
| 79 | +question: "Only pnpm-lock.yaml is conflicted. Regenerate and continue?" |
| 80 | +header: "Simple Resolution" |
| 81 | +options: |
| 82 | + - label: "Yes, run one-liner" |
| 83 | + description: "pnpm install && gt add -A && gt continue" |
| 84 | + - label: "Let me inspect first" |
| 85 | + description: "Show git diff pnpm-lock.yaml before proceeding" |
| 86 | +``` |
| 87 | + |
| 88 | +If confirmed → Execute → Check output of `gt continue`: |
| 89 | +- Another conflict → Loop back to step 3 (Gather Diagnostics) |
| 90 | +- Success message → Proceed to step 6 (Success & Reminder) |
| 91 | + |
| 92 | +#### Complex Conflict Resolution |
| 93 | + |
| 94 | +For each non-lockfile conflict: |
| 95 | + |
| 96 | +**a) Show the conflict**: |
| 97 | +```bash |
| 98 | +git diff <file> |
| 99 | +``` |
| 100 | + |
| 101 | +**b) Explain the conflict** (extract from diff): |
| 102 | +- What changed in base (HEAD) |
| 103 | +- What changed in branch (incoming) |
| 104 | +- Why it conflicts |
| 105 | + |
| 106 | +**c) Ask resolution strategy** using AskUserQuestion: |
| 107 | +``` |
| 108 | +question: "How to resolve <file>?" |
| 109 | +header: "Resolution" |
| 110 | +options: |
| 111 | + - label: "--theirs (main's version)" |
| 112 | + description: "Accept base branch - good for style/formatting consistency" |
| 113 | + - label: "--ours (branch's version)" |
| 114 | + description: "Keep your branch changes - good for features/dependencies" |
| 115 | + - label: "Manual edit" |
| 116 | + description: "I'll resolve it manually, just continue after I'm done" |
| 117 | + - label: "Show original file" |
| 118 | + description: "Show git show HEAD:<file> and git show :<stage>:<file> to inspect" |
| 119 | +``` |
| 120 | + |
| 121 | +**d) Execute choice**: |
| 122 | +- `--theirs`: `git checkout --theirs <file>` |
| 123 | +- `--ours`: `git checkout --ours <file>` |
| 124 | +- Manual: Wait for user confirmation |
| 125 | +- Show original: Display and ask again |
| 126 | + |
| 127 | +**e) After all non-lockfile conflicts resolved**: |
| 128 | +```bash |
| 129 | +pnpm install && gt add -A && gt continue |
| 130 | +``` |
| 131 | + |
| 132 | +**f) Check output of `gt continue`**: |
| 133 | +- Another conflict → Loop back to step 3 (Gather Diagnostics) |
| 134 | +- Success message → Proceed to step 6 (Success & Reminder) |
| 135 | + |
| 136 | +### 5. Handle Broken Lockfile |
| 137 | + |
| 138 | +If diagnostics show "broken lockfile" warning: |
| 139 | + |
| 140 | +Use AskUserQuestion: |
| 141 | +``` |
| 142 | +question: "Lockfile is corrupted. Delete and regenerate?" |
| 143 | +header: "Broken Lockfile" |
| 144 | +options: |
| 145 | + - label: "Yes, delete and regenerate" |
| 146 | + description: "rm pnpm-lock.yaml && pnpm install && gt add -A && gt continue" |
| 147 | + - label: "Try pnpm install first" |
| 148 | + description: "pnpm might auto-fix, try without deleting first" |
| 149 | +``` |
| 150 | + |
| 151 | +After executing choice, check output of command: |
| 152 | +- Another conflict → Loop back to step 3 (Gather Diagnostics) |
| 153 | +- Success message → Proceed to step 6 (Success & Reminder) |
| 154 | + |
| 155 | +### 6. Success & Reminder |
| 156 | + |
| 157 | +When `gt restack` completes without conflicts: |
| 158 | + |
| 159 | +``` |
| 160 | +Restack completed successfully! |
| 161 | +
|
| 162 | +Next step: Force push your stack |
| 163 | + gt stack submit --force |
| 164 | + # Or individual branch: |
| 165 | + git push --force-with-lease origin <branch-name> |
| 166 | +
|
| 167 | +Note: Always use --force-with-lease for safety |
| 168 | +``` |
| 169 | + |
| 170 | +## Quick Reference |
| 171 | + |
| 172 | +**Simple lockfile conflict**: |
| 173 | +```bash |
| 174 | +pnpm install && gt add -A && gt continue |
| 175 | +``` |
| 176 | + |
| 177 | +**Multiple files conflicted**: |
| 178 | +```bash |
| 179 | +git diff <file> # Inspect |
| 180 | +git checkout --ours/--theirs <file> # Resolve |
| 181 | +pnpm install && gt add -A && gt continue |
| 182 | +``` |
| 183 | + |
| 184 | +**Broken lockfile**: |
| 185 | +```bash |
| 186 | +rm pnpm-lock.yaml |
| 187 | +pnpm install && gt add -A && gt continue |
| 188 | +``` |
| 189 | + |
| 190 | +**Cancel restack**: |
| 191 | +```bash |
| 192 | +gt abort |
| 193 | +``` |
| 194 | + |
| 195 | +## Resolution Strategy Guide |
| 196 | + |
| 197 | +**When to use `--theirs` (accept main's version)**: |
| 198 | +- Style/formatting conflicts (e.g., quoted vs unquoted YAML) |
| 199 | +- Configuration files where consistency with main matters |
| 200 | +- Files you didn't intentionally change |
| 201 | + |
| 202 | +**When to use `--ours` (keep branch's version)**: |
| 203 | +- Your branch added dependencies (e.g., pnpm-workspace.yaml) |
| 204 | +- Feature changes you need to preserve |
| 205 | +- Files where your changes are the whole point |
| 206 | + |
| 207 | +**Rule of thumb**: When in doubt, choose consistency with main (`--theirs`). |
| 208 | + |
| 209 | +## Troubleshooting |
| 210 | + |
| 211 | +**Problem**: `gt continue` fails with error |
| 212 | +**Solution**: Check `git status` for unresolved conflicts or unstaged files |
| 213 | + |
| 214 | +**Problem**: pnpm install shows warnings about bin files |
| 215 | +**Solution**: Usually safe to ignore - supabase CLI has known installation quirks |
| 216 | + |
| 217 | +**Problem**: Not sure whether to use --ours or --theirs |
| 218 | +**Solution**: Skill will show both versions and explain - use AskUserQuestion to decide |
| 219 | + |
| 220 | +**Problem**: Multiple files conflicted, unclear which to resolve first |
| 221 | +**Solution**: Skill resolves non-lockfiles first, then regenerates lockfile last |
0 commit comments