resolve-git-conflicts
关于
This Claude Skill helps developers resolve Git merge, rebase, and cherry-pick conflicts by identifying conflict sources, reading markers, and choosing resolution strategies. It provides safe recovery options, including continuing operations or aborting failed merges/rebases. Use it when Git commands report conflicts or when you need to safely restart failed version control operations.
快速安装
Claude Code
推荐npx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/resolve-git-conflicts在 Claude Code 中复制并粘贴此命令以安装该技能
技能文档
Resolve Git Conflicts
Identify, resolve, recover from merge and rebase conflicts.
When Use
git mergeorgit rebasereports conflictsgit cherry-pickcannot apply cleanlygit pullresults in conflicting changesgit stash popconflicts with current working tree
Inputs
- Required: Repository with active conflicts
- Optional: Preferred resolution strategy (ours, theirs, manual)
- Optional: Context about which changes should take priority
Steps
Step 1: Identify Conflict Source
Determine what operation 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 you which files have conflicts and what operation in progress.
Got: git status shows files listed under "Unmerged paths" and indicates active operation.
If fail: git status shows clean tree but you expected conflicts? Operation may have already been completed or aborted. Check git log for recent activity.
Step 2: Read Conflict Markers
Open each conflicting file. Locate conflict markers:
<<<<<<< HEAD
// Your current branch's version
const result = calculateWeightedMean(data, weights);
=======
// Incoming branch's version
const result = computeWeightedAverage(data, weights);
>>>>>>> feature/rename-functions
<<<<<<< HEADto=======: Your current branch (or branch you are rebasing onto)=======to>>>>>>>: Incoming changes (branch being merged or commit being applied)
Got: Each conflicting file contains one or more blocks with <<<<<<<, =======, >>>>>>> markers.
If fail: No markers found but files show as conflicting? Conflict may be binary file or deleted-vs-modified conflict. Check git diff --name-only --diff-filter=U for full list.
Step 3: Choose Resolution Strategy
Manual merge (most common): Edit file to combine both changes logically. Then remove all conflict markers.
Accept ours (keep current branch version):
# 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 branch version):
# 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
Got: After resolution, file contains correct merged content with no remaining conflict markers.
If fail: Chose wrong side? Re-read conflicting version from merge base. During merge, git checkout -m path/to/file re-creates conflict markers so you can try again.
Step 4: Mark Files as Resolved
After editing each conflicting file:
# Stage the resolved file
git add path/to/resolved-file.R
# Check remaining conflicts
git status
Repeat for every file listed under "Unmerged paths".
Got: All files move from "Unmerged paths" to "Changes to be committed". No conflict markers remain in any file.
If fail: git add fails or markers remain? Re-open file and ensure all <<<<<<<, =======, >>>>>>> lines removed.
Step 5: Continue the Operation
Once all conflicts 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"
Got: Operation completes. git status shows clean working tree (or moves to next commit during rebase).
If fail: Continue command fails? Check git status for remaining unresolved files. All conflicts must be resolved before continue.
Step 6: Abort if Needed
Resolution too complex or chose wrong approach? Abort safely:
# Abort merge
git merge --abort
# Abort rebase
git rebase --abort
# Abort cherry-pick
git cherry-pick --abort
Got: Repository returns to state before operation started. No data loss.
If fail: Abort fails (rare)? Check git reflog to find commit before operation. Then git reset --hard <commit> to restore it. Use with caution — discards uncommitted changes.
Step 7: Verify Resolution
After operation 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.)
Got: Clean working tree, correct merge history, tests pass.
If fail: Tests fail after resolution? Merge may have introduced logical errors even though syntax conflicts resolved. Review diff careful and fix.
Checks
- No conflict markers (
<<<<<<<,=======,>>>>>>>) remain in any file -
git statusshows clean working tree - Merge/rebase history correct in
git log - Tests pass after conflict resolution
- No unintended changes introduced
Pitfalls
- Blindly accept one side:
--oursor--theirsdiscards other side entirely. Only use when certain one version completely correct. - Leave conflict markers in code: Always search entire file for remaining markers after editing. Partial resolution breaks the code.
- Amend during rebase: During interactive rebase, do not
--amendunless rebase step specifically calls for it. Usegit rebase --continueinstead. - Lose work on abort:
git rebase --abortandgit merge --abortdiscard all resolution work. Only abort if want to start over. - No test after resolution: Syntactically clean merge can still be logically wrong. Always run tests.
- Force-push after rebase: After rebasing shared branch, coordinate with collaborators before force-pushing — it rewrites history.
See Also
commit-changes- committing after conflict resolutionmanage-git-branches- branch workflows that lead to conflictsconfigure-git-repository- repository setup and merge strategies
GitHub 仓库
相关推荐技能
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界面,并指导如何在两种环境间无缝迁移会话。它能分析任务复杂度、迭代需求等要素,推荐最优工作界面和工作流。关键特性包括会话状态管理、环境切换指导和上下文优化建议。
