選項
首頁首頁 Skill 程式碼審查 pull-changes-resolve-conflicts

pull-changes-resolve-conflicts

cognitedata/builder-skills cognitedata/builder-skills

在多貢獻者專案(包括 Flows 應用)中,從主分支或其他分支獲取更新的標準工作流程,可避免在未經通知的情況下丟棄現有工作。該流程指導使用者如何執行獲取與合併操作,要求明確列出合併衝突,透過對話記錄和倉庫上下文分析雙方程式碼的差異,提供按優先順序排序的建議,並在修改衝突標記或完成合並之前獲取使用者確認。觸發場景包括:拉取主分支、合併主分支、合併 origin 分支、執行 rebase 操作、出現合併衝突以及存在未合併的暫存區。

...展開全部
11
更新時間 2026-08-26

關於 pull-changes-resolve-conflicts

這是一套專為多貢獻者專案設計的引導式工作流程,用於將一個分支整合到另一個分支中(通常是把 main 分支拉取或合併到特性分支中),同時避免無意中丟棄他人已完成的程式碼工作。該流程適用於任何基於 Git 的團隊協作模式,尤其常見於 Flows/React 應用——這類應用中的衝突往往集中在應用外殼、頂部導航、路由模組以及共享的 lib/ 或 hooks/ 目錄中。其核心原則是,在進行分析之前絕不能擅自認定“main 分支的程式碼必勝”或“我方程式碼必勝”,且在修改任何衝突標記之前,必須讓使用者清楚瞭解所涉及的權衡因素。

工作流程分階段進行:首先執行獲取並整合操作(除非使用者要求使用 rebase,否則優先採用 git fetch 後再執行 git merge origin/main);接著明確列出所有未合併的檔案,並簡要說明導致差異的原因;隨後透過對話歷史記錄、倉庫中的相關文件(如 PRD.md 或近期提交記錄),以及透過 git show :2:path 檢視我方程式碼內容、git show :3:path 檢視對方程式碼內容來分析衝突。衝突會被分為三類:正交衝突(可安全合併)、重疊衝突(需手動選擇或合併),以及資料損壞風險衝突(由錯誤合併導致的重複程式碼塊)。分析結果會以優先順序排序的形式呈現為建議和明確的問題,優先順序從 P0(結構性/產品層面的變更,如路由被刪除、功能被移除、資料或 API 介面協議發生變化)到 P3(介面層面的微調,如間距、類名調整)不等。

該工具嚴格執行“不得自動隱藏衝突”的硬性規則:在使用者同意處理方案或明確接受建議之前,不會刪除衝突標記,也不會執行 git add 操作。它會在遇到衝突時暫停處理,而非強行繼續處理大檔案,並支援透過 git merge --abort 或 git rebase --abort 來中止當前操作。此外,它還列出了應避免的錯誤做法,比如在整個倉庫中統一選擇 --ours 或 --theirs,或在沒有簡短總結的情況下將衝突列表隱藏在冗長的程式碼片段中。相關的可選命令示例和合並訊息模板均放在附帶的 reference.md 檔案中。

常見問題

什麼時候應該使用此工具?

每當您需要將另一個分支(通常是 main 分支)整合到當前的特性分支中,或者在執行合併或 rebase 後發現 git status 顯示有未合併的路徑時,都可以使用它。該工具適用於任何基於 Git 的團隊協作模式,Flows/React 應用是典型的應用場景。

它會自動解決衝突而不需要我操作嗎?

不會。有嚴格的硬性規則禁止自動隱藏衝突:在您同意處理方案或明確要求按照其建議操作之前,它不會刪除衝突標記,也不會執行 git add 操作。它會先在遇到衝突時暫停,並將衝突情況告知您。

它是如何決定先處理哪些衝突的?

衝突會按照影響程度排序,從 P0 級別(結構性/產品層面的變更,如路由被刪除、功能被移除、資料或 API 介面協議發生變化)到 P3 級別(介面層面的微調,如間距、類名和文案調整)依次處理。

在編輯之前,它依靠哪些資訊來分析衝突?

它會參考關於該分支所包含功能的對話歷史記錄、倉庫中的相關文件(如 PRD.md 或近期提交記錄)以及檔案歸屬資訊,同時透過 git show :2:path 檢視我方程式碼內容,再透過 git show :3:path 檢視對方程式碼內容,以此來分析衝突。

如果我只是想中止合併操作怎麼辦?

該工具支援根據情況執行 git merge --abort 或 git rebase --abort 操作,並會提示您該操作會導致正在進行的整合狀態丟失。

所有檔案

2 個檔案 reference.md 0.7 KB 檢視 SKILL.md 5.5 KB 檢視

在 GitHub 上查看

Use this skill whenever integrating another branch (usually main) into the current feature branch, or when git status shows unmerged paths after a merge or rebase. Applies to any Git-based team workflow; Flows/React apps are a common case where conflicts cluster in app shells and shared libraries.

Goals

  • Preserve intentional work on the current branch; do not assume “main wins” or “ours wins” without analysis.
  • Make trade-offs visible to the user before any conflict resolution edits.
  • Order discussion by impact: structural / feature / API / data-model changes before styling, copy, or spacing.

Hard rules

  1. No silent resolution — Do not remove <<<<<<< / ======= / >>>>>>> or run git add on conflicted files until the user has agreed to the plan (or explicitly says “use your recommendations”).
  2. Stop at conflicts — If a merge or rebase introduces conflicts, pause and report; do not bulldoze through large files by picking one side wholesale unless the user explicitly requests that.
  3. Prioritize impact — When presenting conflicts, group and order roughly as:
    • P0 — Structural / product: removed routes, deleted modules, dropped features, changed data or API contracts, SDK or schema changes, auth or routing shell.
    • P1 — Behavior: logic, hooks, queries, filters, error handling, loading states.
    • P2 — UI structure: layout regions, new or removed sections, navigation.
    • P3 — Presentation: tokens, spacing, class names, copy tweaks.

Workflow

1. Fetch and integrate (or diagnose)

  • Prefer git fetch then git merge origin/main (or the named branch) unless the user asked for rebase.
  • If merge is already in progress, run git status and list every unmerged file.

2. Report conflicts to the user (explicit)

Output a clear list:

  • Branch state: current branch, target branch (e.g. origin/main), merge vs rebase.
  • Unmerged files: paths only, then optionally git diff --name-only --diff-filter=U.
  • Per file (short): one line on what diverged (e.g. “AlertsPage — layout + new data scope”) if inferable from paths and git diff without resolving.

3. Analyze before editing

Use all of:

  • Conversation history — What was the user or team trying to ship on this branch?
  • Repo signals — Product or architecture docs if present (e.g. PRD.md), recent commits on the current branch, file ownership (e.g. large feature module vs shared lib/).
  • Conflict hunks — git show :2:path (ours) vs git show :3:path (theirs) during merge, or read conflict markers; identify duplicated vs orthogonal changes.

Classify each conflicted area as:

  • Orthogonal — safe to combine (e.g. import sort + new prop).
  • Overlapping — must choose or manually merge (same lines).
  • Corruption risk — duplicated blocks (common after bad merges); flag and recommend reconstructing from one side then re-applying the other side’s intent manually.

4. Recommendations + questions (required)

Present to the user:

  1. Summary table or bullets — file → recommended side or “manual merge” → one-line why.
  2. Ordered by P0 → P3 — call out anything that removes a feature or changes public behavior first.
  3. Explicit questions — anything ambiguous (e.g. “Keep main’s global behavior or the branch’s scoped variant?”).
  4. Ask for direction — e.g. “Reply with: (a) follow recommendations, (b) keep branch for file X, (c) keep main for file Y, (d) abort merge.”

Only after the user confirms (or gives a precise mapping), apply resolutions:

  • Prefer small, surgical edits; preserve both sides’ intent when possible.
  • Re-run git status; ensure no conflict markers remain; run tests or lint the user cares about for touched areas.

5. If the user wants to abort

  • git merge --abort or git rebase --abort as appropriate; confirm they lose in-progress integration state for that operation.

Anti-patterns (do not do)

  • Picking --ours / --theirs on the whole repo without user approval.
  • “Resolving” by deleting a feature branch’s work because main touched the same file.
  • Hiding conflict lists inside a long code dump without a short executive summary.
  • Fixing low-impact style conflicts first while leaving P0 decisions implicit.

Quick reference

  • Ours vs theirs (merge): stage 2 = current branch (HEAD), stage 3 = incoming (MERGE_HEAD). Verify with git checkout --conflict=merge <file> if needed.
  • Typical high-touch paths in full-stack or Flows apps: root app shell, top navigation, route modules, and shared lib/ or hooks/.

For optional command snippets and a merge message template, see reference.md.

所有檔案

0 個檔案

安裝 pull-changes-resolve-conflicts

將技能檔案下載並解壓到您的 .claude/skills/ 目錄中。

下載 ZIP

複製儲存庫並將技能檔案複製到您的專案中。

git clone https://github.com/cognitedata/builder-skills/blob/main/skills/pull-changes-resolve-conflicts/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

複製 複製
快速設定: 將該技能資料夾複製到 .claude/skills/ 目錄中,Claude 會自動檢測並使用該技能。

相關技能

code-simplify
更新時間 2026-07-02
requesting-code-review
更新時間 2026-06-29
Git Commit Helper
更新時間 2026-06-29
commit-standards
更新時間 2026-06-29
OR