agentleFS
narenaryannarenaryan/agent-skills/skills/git/git-advanced-merging/SKILL.md

git-advanced-merging

Skill0 starsChanged 39 days agoMITView on GitHub

Use when resolving non-trivial merge conflicts, choosing a merge strategy, or undoing a merge — covers -X options, diff3 markers, strategy vs option, reset vs revert -m, and re-merging reverted branches

  • Deletes or force-pushes

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Default hides the common ancestor.

    line 10
  2. Very specific:

    Gotcha: after revert -m 1, re-merging the same branch pulls only new commits — Git thinks the rest is already merged.

    line 65

≈ “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

Advanced Git Merging

Conflict Marker Style

Default hides the common ancestor. Show it:

git config --global merge.conflictStyle zdiff3   # git 2.35+; else diff3
git checkout --conflict=diff3 path               # re-render existing conflict

Markers become <<<ours / ||| base / === / theirs >>> — resolution is far easier.

Side-Picking

git checkout --ours path
git checkout --theirs path
git add path

During rebase, ours/theirs swap: "theirs" = the commits being replayed.

Strategy (-s) vs Strategy Option (-X)

  • Strategy (-s) picks the algorithm: ort (default), recursive, resolve, octopus, ours, subtree.
  • Option (-X) tunes a strategy. -X ours only breaks ties; non-conflicting changes still merge.
git merge -X ours feature           # merge all, prefer ours on conflict
git merge -s ours feature           # fake-merge: record, keep tree unchanged
git merge -X ignore-all-space feature
git merge -X patience feature       # better diff for reordered blocks

-s ours says "we abandon their work but don't want future merges replaying it."

Inspecting

git ls-files -u                     # stages 1=base, 2=ours, 3=theirs
git show :1:f > base; git show :2:f > ours; git show :3:f > theirs
git merge-file -p ours base theirs > resolved
git log --merge -p path             # commits on either side touching file
git log --left-right HEAD...MERGE_HEAD

Abort

git merge --abort                   # before committing
git reset --merge                   # equivalent

Undoing a Completed Merge

Local only: git reset --hard ORIG_HEAD

Already pushed: git revert -m 1 <merge-sha> (keep mainline, drop feature side).

Gotcha: after revert -m 1, re-merging the same branch pulls only new commits — Git thinks the rest is already merged. Fix:

git revert <revert-commit>          # un-revert
git merge feature                   # clean re-merge

Pitfalls

  • No -s theirs exists; do -s ours on the other branch then merge back.
  • Octopus strategy refuses to auto-resolve conflicts.
  • For recurring conflicts, enable rerere.

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.