agentleFS
naingthetnaingthet/agent-skills/skills/rebase-recovery/SKILL.md

rebase-recovery

Skill1 starsChanged 3 months agoMITView on GitHub

Move a branch onto a base that has moved, without silently reverting what landed in the meantime, and recover the work if a reset or rebase already destroyed it. Use when rebasing onto a moved main, restacking a branch whose parent PR was squash-merged, or when the user says "my PR is reverting things I never touched", "I lost my changes after a rebase", "rebase this onto main", or "restack this branch".

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 5 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If the reverted change sits in a file you also edited legitimately, your changed-files list looks exactly as expected.

    line 28
  2. Distinctive:

    If this conflicts, resolve the conflict.

    line 54
  3. Very specific:

    When a stacked PR is squash-merged, the base gains one new commit whose content matches your work but whose identity does not.

    line 59
  4. Very specific:

    Use --onto with the recorded fork point of the *child* branch, or branch fresh from the base and reapply only the child's own changes.

    line 64
  5. Distinctive:

    After any history surgery:

    line 69
  6. Distinctive:

    Read the hunks, not just the file list.

    line 75
  7. Distinctive:

    If you only want the file contents, take a path-scoped patch instead:

    line 99
  8. Very specific:

    Use git apply -3, not git apply.

    line 107

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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

Rebase recovery

Rebasing is safe. The damage comes from reaching for git reset --soft when a rebase conflicts, which trades a conflict you can see for a revert you cannot.

The trap

git reset --soft <base> moves the branch pointer and leaves your working tree alone. The commit you make next therefore pairs the tree you already had with the new base as its parent. Git records that as a change, so everything that landed on the base since you branched is reverted inside your commit.

git reset --soft origin/main   # branch pointer moves, tree does not
git commit -m "rebased"        # this commit now reverts everyone else's work

Nothing warns you, and a rebase would have raised a conflict on the same content.

Why review misses it

If the reverted change sits in a file you also edited legitimately, your changed-files list looks exactly as expected. One file, the file you meant to touch. The revert is a hunk inside it:

-THEIR SECURITY FIX
+line1
 line2
 line3
+MY FEATURE

Scanning file names does not catch this. Only reading hunks does.

Move a branch correctly

Replay your commits onto the new base and name the old base explicitly:

git rebase --onto <new-base> <old-base> <branch>

<old-base> is where your branch forked. git merge-base <branch> <new-base> finds it, but only while the base still contains that commit. Record the fork point before you start, because a squash merge or a force push can remove it.

If this conflicts, resolve the conflict. A conflict means two changes touch the same lines, which is information. Do not switch to a reset to make it quiet.

Squash-merged parents

When a stacked PR is squash-merged, the base gains one new commit whose content matches your work but whose identity does not. Git cannot tell your commits are already in, so a plain git rebase <base> replays them and conflicts against the squashed version.

Use --onto with the recorded fork point of the child branch, or branch fresh from the base and reapply only the child's own changes.

Check before you push

After any history surgery:

git diff <base>...HEAD

Read the hunks, not just the file list. Every deletion should be a line you wrote. A deletion you do not recognize is someone else's work being reverted.

git range-diff <old-base>..<old-tip> <base>..HEAD shows how your commits changed shape. Commits that fail to pair up mean the rewrite did more than move them.

Recover work you already destroyed

The old tip is still in the reflog. Nothing is lost until the reflog expires.

git reflog <branch>          # find the tip from before the surgery
PRE=<that sha>
OLD=$(git merge-base $PRE <base>)

Then replay the original commits, which keeps their messages and authorship:

git checkout -B recovered $PRE
git rebase --onto <base> $OLD recovered

If you only want the file contents, take a path-scoped patch instead:

git diff $OLD $PRE -- <your paths> > /tmp/mine.patch
git checkout -b recovered <base>
git apply -3 /tmp/mine.patch

Use git apply -3, not git apply. Once the base has moved, the patch context lines no longer match and a plain apply fails with patch does not apply. The -3 flag falls back to a three-way merge using the blob index and succeeds.

Report what you did

Say which commits you replayed, what the fork point was, and what the diff against the base contains now. If you recovered from a destroyed branch, say that the old tip is still in the reflog and give its sha, so the user can check your work rather than trust 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.