返回技能列表

resolve-git-conflicts

pjt222
更新于 2 days ago
6 次查看
17
2
17
在 GitHub 上查看
设计aiapi

关于

This Claude Skill helps developers resolve Git merge and rebase conflicts with safe recovery options. It identifies conflict sources, reads markers, offers resolution strategies, and allows safe continuation or abortion of operations. Use it when git merge/rebase/cherry-pick/stash pop or pull operations report conflicts.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/resolve-git-conflicts

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Resolve Git Conflicts

ID, resolve, recover from merge + rebase conflicts.

Use When

  • git merge or git rebase reports conflicts
  • git cherry-pick can't apply cleanly
  • git pull → conflicts
  • git stash pop conflicts w/ working tree

In

  • Required: Repo w/ active conflicts
  • Optional: Preferred strategy (ours, theirs, manual)
  • Optional: Ctx about which changes priority

Do

Step 1: ID Source

Determine what op caused conflict:

# Check current status
git status

# Look for indicators:
# "You have unmerged paths" — merge conflict
# "rebase in progress" — rebase conflict
# "cherry-pick in progress" — cherry-pick conflict

Status output tells which files have conflicts + active op.

git status shows files under "Unmerged paths" + indicates active op.

If err: git status clean tree but expected conflicts → op may have completed/aborted. Check git log recent activity.

Step 2: Read Markers

Open each conflicting file + locate markers:

<<<<<<< HEAD
// Your current branch's version
const result = calculateWeightedMean(data, weights);
=======
// Incoming branch's version
const result = computeWeightedAverage(data, weights);
>>>>>>> feature/rename-functions
  • <<<<<<< HEAD to =======: Your current branch (or rebasing onto)
  • ======= to >>>>>>>: Incoming changes (merging branch or applying commit)

→ Each conflicting file has 1+ blocks w/ <<<<<<<, =======, >>>>>>> markers.

If err: no markers found but files conflicting → may be binary or deleted-vs-modified. Check git diff --name-only --diff-filter=U for full list.

Step 3: Choose Strategy

Manual merge (most common): Edit file to combine both changes logically, remove all markers.

Accept ours (keep current branch):

# For a single file
git checkout --ours path/to/file.R
git add path/to/file.R

# For all conflicts
git checkout --ours .
git add -A

Accept theirs (keep incoming):

# For a single file
git checkout --theirs path/to/file.R
git add path/to/file.R

# For all conflicts
git checkout --theirs .
git add -A

→ After resolution, file has correct merged content w/ no remaining markers.

If err: chose wrong side → re-read conflicting ver from merge base. During merge, git checkout -m path/to/file re-creates markers so you can try again.

Step 4: Mark Resolved

After editing each file:

# Stage the resolved file
git add path/to/resolved-file.R

# Check remaining conflicts
git status

Repeat for every file under "Unmerged paths".

→ All files move "Unmerged paths" → "Changes to be committed". No markers remain.

If err: git add fails or markers remain → re-open file + ensure all <<<<<<<, =======, >>>>>>> lines removed.

Step 5: Continue Op

Once all resolved:

For merge:

git commit
# Git auto-populates the merge commit message

For rebase:

git rebase --continue
# May encounter more conflicts on subsequent commits — repeat steps 2-4

For cherry-pick:

git cherry-pick --continue

For stash pop:

# Stash pop conflicts don't need a continue — just commit or reset
git add .
git commit -m "Apply stashed changes with conflict resolution"

→ Op completes. git status shows clean tree (or moves to next commit during rebase).

If err: continue cmd fails → check git status for remaining unresolved. All conflicts must resolve before continuing.

Step 6: Abort if Needed

Resolution too complex or wrong approach → abort safely:

# Abort merge
git merge --abort

# Abort rebase
git rebase --abort

# Abort cherry-pick
git cherry-pick --abort

→ Repo returns to state before op started. No data loss.

If err: abort fails (rare) → check git reflog to find commit before op + git reset --hard <commit> to restore. Use w/ caution — discards uncommitted.

Step 7: Verify

After op completes:

# Verify clean working tree
git status

# Check that the merge/rebase result is correct
git log --oneline -5
git diff HEAD~1

# Run tests to confirm nothing is broken
# (language-specific: devtools::test(), npm test, cargo test, etc.)

→ Clean tree, correct merge history, tests pass.

If err: tests fail after resolution → merge may have introduced logical errs even though syntax conflicts resolved. Review diff carefully + fix.

Check

  • No markers (<<<<<<<, =======, >>>>>>>) remain
  • git status shows clean tree
  • Merge/rebase history correct in git log
  • Tests pass after resolution
  • No unintended changes introduced

Traps

  • Blindly accept one side: --ours/--theirs discards other side entirely. Only use when certain one ver completely correct.
  • Leave markers in code: Always search entire file for remaining markers after edit. Partial resolution breaks code.
  • Amend during rebase: Interactive rebase → don't --amend unless step specifically calls for it. Use git rebase --continue instead.
  • Lose work on abort: git rebase --abort + git merge --abort discard all resolution work. Only abort to start over.
  • Not testing after resolution: Syntactically clean merge can still be logically wrong. Always run tests.
  • Force-push after rebase: After rebasing shared branch, coord w/ collaborators before force-push, rewrites history.

  • commit-changes — committing after resolution
  • manage-git-branches — branch workflows leading to conflicts
  • configure-git-repository — repo setup + merge strategies

GitHub 仓库

pjt222/agent-almanac
路径: i18n/caveman-ultra/skills/resolve-git-conflicts
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

executing-plans

设计

该Skill用于当开发者提供完整实施计划时,以受控批次方式执行代码实现。它会先审阅计划并提出疑问,然后分批次执行任务(默认每批3个任务),并在批次间暂停等待审查。关键特性包括分批次执行、内置检查点和架构师审查机制,确保复杂系统实现的可控性。

查看技能

requesting-code-review

设计

该Skill可在完成任务、实现主要功能或合并代码前自动调度代码审查子代理,确保实现符合需求和计划。它支持通过指定git SHA范围进行精准的代码变更审查,帮助开发者在关键节点及时发现潜在问题。核心原则是"早审查、勤审查",适用于开发流程的各个关键阶段。

查看技能

connect-mcp-server

设计

这个Skill指导开发者如何将MCP服务器连接到Claude Code,支持HTTP、stdio和SSE三种传输协议。它涵盖了从安装配置到认证安全的完整流程,适用于集成GitHub、Notion、数据库等外部服务。当开发者需要添加集成、配置外部工具或提及MCP相关功能时,这个Skill能提供实用的操作指南。

查看技能

web-cli-teleport

设计

该Skill帮助开发者根据任务特性选择Claude Code的Web或CLI界面,并指导如何在两种环境间无缝迁移会话。它能分析任务复杂度、迭代需求等要素,推荐最优工作界面和工作流。关键特性包括会话状态管理、环境切换指导和上下文优化建议。

查看技能