git-rebuild-history

git-rebuild-history is a skill for Claude Code, Codex from magic3007/dotfiles. It costs 193 tokens per session (7,851 once invoked), scanned C, original, MIT.

A workflow for rebuilding a Git branch so its history contains only the useful final changes, rather than exploratory commits. Git is the version-control system that stores project history and branches.

In plain words
What is it for?
Use it before merging a feature branch whose history contains exploration or whose uncommitted work needs to be split into clean commits.
Why use it?
It removes dead ends, temporary files, reverted approaches, and work-in-progress commits that make a branch difficult to review or merge. The approach reconstructs commits from the final difference against the correct merge base.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: positional $N argument.

Good fit Use it before merging a feature branch whose history contains exploration or whose uncommitted work needs to be split into clean commits.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/magic3007/dotfiles/git-rebuild-history
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add magic3007/dotfiles --skill git-rebuild-history
Clone the repo
git clone --depth 1 https://github.com/magic3007/dotfiles

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for git-rebuild-history

README.md
[![agentmods](https://agentmods.dev/badge/skills/magic3007/dotfiles/git-rebuild-history/github.svg)](https://agentmods.dev/skills/magic3007/dotfiles/git-rebuild-history)
Your own site
<a href="https://agentmods.dev/skills/magic3007/dotfiles/git-rebuild-history"><img src="https://agentmods.dev/badge/skills/magic3007/dotfiles/git-rebuild-history/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for git-rebuild-history

Your own site · 80×15
<a href="https://agentmods.dev/skills/magic3007/dotfiles/git-rebuild-history"><img src="https://agentmods.dev/badge/skills/magic3007/dotfiles/git-rebuild-history.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 193 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 7,851 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00193 $0.07851
Opus 5.5 $0.00077 $0.03140
Sonnet 5.5 $0.00039 $0.01570
Haiku 4.5 $0.00019 $0.00785

Measured 19d ago against content hash 3bc1e6e06ede, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade C, and why

git-rebuild-history scanned grade C with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 19d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Recursive force deletehighDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

rm -rf "$d"
skills/git-rebuild-history/SKILL.md · 531 lines

How it starts

The opening of the file, as written. The whole thing — 531 lines — stays where its author put it; the contents beside it link to each section on GitHub.

重建分支历史,让探索从不进入历史

分支要合并,但历史里混着探索。目标不是"把探索藏起来",而是让探索从未存在过。

为什么是重建,不是 rebase

rebase -i 只能 drop / squash / reword 已存在的 commit。探索的形状恰恰是它处理不了的:

  • 加了又删的文件(approach_a.py 提交过,后来删了):drop 掉"加"那条,"删"那条就变成删除一个不存在的文件;两条都 drop 文件才干净,但你要手工找出所有这种配对。
  • 同一路径的反复改写(thing.py 提交成 v1、v2、final):三条 commit 动同一个文件,drop 任何一条都会让后面的 patch 冲突或落空。实测里 git cherry-pick 这种"删掉旧内容再加新内容"的 commit 会直接变成空 commit。
  • squash 也不能免俗:三条合成一条,diff 链里仍留着 v1 的痕迹,只是被压平了。

重建换了个思路:不问"这些 commit 哪些该留",而是问"最终状态相对 base 改了什么",然后按架构分层重新切一遍。探索根本不在输入里,所以不可能出现在输出里。

代价是 commit 边界由你重新决定。原来那些边界本来就不值得沿用——它们是探索的脚印。

0. 先确定两个变量

全文用 $BASE 和 $CHECK,现在就定下来。

$BASE:从哪开始。 是合并目标分支,不是当前分支的 upstream。

BASE_REF=""
for ref in origin/master master origin/main main; do
  git rev-parse --verify -q "$ref" >/dev/null 2>&1 && { BASE_REF=$ref; break; }
done
[ -n "$BASE_REF" ] || { echo "找不到合并目标分支,手动指定 BASE_REF" >&2; exit 1; }
BASE=$(git merge-base HEAD "$BASE_REF")
echo "BASE_REF=$BASE_REF  BASE=$BASE  $(git log -1 --format=%s "$BASE")"

两个坑:

  • 不要用 @{upstream}。 它是当前分支自己的远端(origin/feat/x),git merge-base HEAD origin/feat/x 得到 HEAD——整个重建从错误起点开始,而且不报错。
  • 不要写 A || B | sed || echo 默认值 这种链。 管道让 sed 即使输入为空也退出 0,|| echo 永远不触发,BASE_REF 静默变成空字符串。用上面的 for 循环逐个 rev-parse --verify。

$BASE 是"这个分支 fork 出去的那个点",不是"master 现在在哪"。用后者会把别人合进 master 的改动也算进你的 diff。

stacked branch(这个分支基于另一个特性分支)要手动把 BASE_REF 设成那个特性分支。

$CHECK:项目自己的检查命令。 从仓库的 Makefile / package.json / CI 配置里读出来,写成一条能跑的字符串。后面每个 commit 都要用它,所以现在就要确定。

ls Makefile makefile GNUmakefile package.json pyproject.toml tox.ini noxfile.py 2>/dev/null
ls .github/workflows/ .gitlab-ci.yml 2>/dev/null | head

典型形态:

CHECK='make check'                       # 有 Makefile
CHECK='PYTHONPATH=$PWD/src pytest -q'    # Python,注意 $PWD 会在 worktree 里展开
CHECK='npm test --silent'                # Node
CHECK='cargo test --quiet'               # Rust
CHECK='go test ./...'                    # Go

一个都没找到(没有构建配置、没有 CI)就自己定一条最小的:跑测试目录、跑类型检查、或至少 import 一遍包。这条检查的作用是抓"某个中间 commit 根本跑不起来",不需要覆盖完整 CI。

Read the full file on GitHub · 531 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 19d ago First seen · 531 lines · 193 tokens per session scan C 3bc1e6e06ede

Subscribe to this mod's changes

git-rebuild-history is a skill published in the GitHub repository magic3007/dotfiles (11 stars, last pushed 5d ago), licensed MIT. It adds 193 tokens to every session and 7,851 once invoked, about $0.0008 per session on Opus 5.5. A static security scan graded it C with 1 finding (recursive force delete). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-11-11.

Related

git-rebuild-history compared with skills from other repositories

git-rebuild-history next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
git-rebuild-historymagic3007/dotfilesSkill115d agoMITC193Claude Code, Codex
merge-readyurmzd/dotfilesSkill64d agoApache-2.0A208Claude Code
landurmzd/dotfilesSkill64d agoApache-2.0A168Claude Code
commiturmzd/dotfilesSkill64d agoApache-2.0A115Claude Code
review-codeooloth/dotfilesSkill24todaynoneA243Claude Code
review-pr-comments-convergeooloth/dotfilesSkill24todaynoneA50Claude Code
review-convergeooloth/dotfilesSkill24todaynoneA57Claude Code