agentleFS
milad-ahmdmilad-ahmd/agent-skills/skills/merge-conflict-resolver/SKILL.md

merge-conflict-resolver

Skill5 starsChanged 18 days agoMITView on GitHub

Resolves git merge, rebase, cherry-pick, revert and stash pop conflicts by working out what each side meant and keeping both intents, instead of picking ours or theirs. A read-only script reports the operation in progress and what "ours" and "theirs" mean for it (they swap during a rebase), each conflicted file and its kind (content, add/add, modify/delete, rename, binary), every hunk's ours, base and theirs text, and the commits on each side that touched the file. Lockfiles such as package-lock.json, yarn.lock or Cargo.lock are regenerated with the package manager, never hand-merged, and a check mode confirms no conflict markers are left before git add and continue. Use when the user asks to resolve or fix merge conflicts, says a rebase or cherry-pick stopped with CONFLICT, sees <<<<<<< HEAD markers in a file, asks whether to keep ours or theirs, has a conflicted package-lock.json, or wants help finishing a stuck merge or rebase.

  • Deletes or force-pushes
  • Installs packages

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 7 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    Write one line per hunk, such as "ours: X because Y.

    line 28
  2. Distinctive:

    Remove every marker line and keep the code consistent: one name, one signature, imports that match what is used.

    line 42
  3. Distinctive:

    Never merge lockfile hunks by hand.

    line 46
  4. Very specific:

    Run the printed command, for example npm install --package-lock-only, pnpm install, yarn install, cargo update --workspace, poetry lock, uv …

    line 50
  5. Distinctive:

    Check the diff of the lockfile against the long-lived branch: only the other side's dependency changes should appear.

    line 51
  6. Very specific:

    Run git checkout --ours/--theirs, -X ours/theirs or -s ours on whole files or the whole merge without reading every hunk.

    line 73
  7. Distinctive:

    Delete or comment out either side's code to make the build pass.

    line 74
  8. Distinctive:

    Run git rebase --skip. It drops the whole commit being replayed.

    line 75
  9. Distinctive:

    Commit, push or force-push unless the user asked for it.

    line 78

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Merge Conflict Resolver

A conflict means two changes touched the same lines, usually for different reasons. A good resolution keeps both reasons unless one makes the other obsolete. Picking a whole side without reading it loses someone's work.

1. See what is in conflict

python3 scripts/conflicts.py              # operation, sides, files, hunks, commits per side
python3 scripts/conflicts.py src/api.ts   # only these paths
python3 scripts/conflicts.py --json       # machine-readable, hunk text never cut

The script only reads. Start with its operation line, for example rebasing feature onto main, commit 3/7. During a rebase, ours is the branch you are rebasing onto and theirs is your own commit being replayed. During a revert, theirs is the code as it was before the reverted commit. A conflicted git stash pop leaves no state file, so the script recognises it by the Updated upstream and Stashed changes marker labels.

Exit codes: 0 nothing to resolve or clean · 1 conflicts present · 2 not a git repository or a git error.

2. Work out what each side meant

For each content hunk, before editing anything, compare ours and theirs against base. Base is what both sides started from, so it shows what each one changed. The script takes base from diff3/zdiff3 markers or rebuilds it from the index. To get it in the file itself next time, set git config merge.conflictStyle zdiff3 (git 2.35 or later).

Then read the commits listed for each side with git show <sha>. The message, the rest of the diff and any linked issue say why the line changed: a bug fix, a rename, a new parameter, a refactor that moved the code. Look past the hunk too, at callers of a renamed function, tests either side added, and the same identifier elsewhere.

Write one line per hunk, such as "ours: X because Y; theirs: Z because W; keep: ...". If you can't say why one side made its change, find out before choosing.

3. Combine the intents

SituationResolution
Both added entries (imports, routes, enum values, list items)Keep both, drop exact duplicates, follow the file's ordering
One side renamed or moved code, the other changed its bodyApply the body change at the new name or location
One side refactored, the other fixed a bug in the old versionRe-apply the fix inside the refactored code
Both changed the same value (timeout = 45 vs 120)Choose by intent from the commit messages. If it is still unclear, ask the user
modify/deleteFind out why it was deleted. If it moved, port the change to the new place. If the feature was removed, drop the change and say so
rename (rename/rename, rename/delete) or add/addChoose one path and one content, then update references to the other
Binary fileAsk which version is right, then git checkout --ours -- <path> or --theirs

Remove every marker line and keep the code consistent: one name, one signature, imports that match what is used.

4. Lockfiles and generated files

Never merge lockfile hunks by hand. The script flags them and prints the regenerate command.

  1. Resolve the manifest first (package.json, Cargo.toml, pyproject.toml, go.mod, Gemfile) using step 2.
  2. Take the lockfile from the long-lived branch: git checkout --ours -- package-lock.json when rebasing onto main, --theirs when merging main into your branch.
  3. Run the printed command, for example npm install --package-lock-only, pnpm install, yarn install, cargo update --workspace, poetry lock, uv lock, bundle install or go mod tidy. Run it from the directory that holds the manifest. These keep versions that are already locked and resolve only what the manifest changed.
  4. Check the diff of the lockfile against the long-lived branch: only the other side's dependency changes should appear.

Generated files (minified bundles, source maps, Jest snapshots, files whose header says generated or DO NOT EDIT) work the same way: resolve the sources, then re-run the generator.

5. Verify

python3 scripts/conflicts.py --check   # exit 1 lists file:line of marker sets left (working tree or staged) and unmerged paths

A Markdown or reST ======= underline is not reported; only a full <<<<<<<, =======, >>>>>>> set counts. Then run the project's build, type check and the tests closest to the changed files. If something fails, fix it according to the intents from step 2.

6. Mark resolved and continue

git add <file> for each resolved file, git rm <file> where removing it was the right call. Then run the continue command the script printed (git rebase --continue, git merge --continue, git cherry-pick --continue, ...). A rebase can stop again on the next commit: go back to step 1. After a stash pop, the stash is kept; suggest git stash drop once the user confirms the result. If the user only asked for the files to be resolved, stop after git add and let them continue.

Report

Per file and hunk: what each side meant, what you kept, and which choices were judgement calls the user should check. Then the verification commands and their results.

Do not

  • Run git checkout --ours/--theirs, -X ours/theirs or -s ours on whole files or the whole merge without reading every hunk.
  • Delete or comment out either side's code to make the build pass.
  • Run git rebase --skip. It drops the whole commit being replayed. Do it only if the user agrees the commit is no longer needed.
  • git add a file that still has markers. Run --check first.
  • Abort the operation or reset the tree on your own. git merge --abort, git rebase --abort and git reset --hard throw away resolution work, so the user decides.
  • Commit, push or force-push unless the user asked for it.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.