squash-commits
Squash all commits on the current branch (relative to the main branch) into a single commit while preserving the branch name. Use when: user wants to squash commits, clean up branch history, compress multiple commits into one, or tidy up before merging. Triggers on: squash commits, 压缩提交, 合并提交, clean up commits, compress commits, squash branch, 整理提交记录, 合并为一个提交. Make sure to use this skill whenever the user mentions squashing, compressing, or cleaning up commit history on a branch, even if they don't use the exact term "squash".
- License 许可
- MIT
- 所属仓库
- Yukiniro/skills
- 最近更新
- 2026-10-17
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- squash-commits
- description
- Squash all commits on the current branch (relative to the main branch) into a single commit while preserving the branch name. Use when: user wants to squash commits, clean up branch history, compress multiple commits into one, or tidy up before merging. Triggers on: squash commits, 压缩提交, 合并提交, clean up commits, compress commits, squash branch, 整理提交记录, 合并为一个提交. Make sure to use this skill whenever the user mentions squashing, compressing, or cleaning up commit history on a branch, even if they don't use the exact term "squash".
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md385 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Squash Commits
Compress all commits on the current feature branch (relative to the main branch) into a single, clean commit. The branch name stays the same — only the commit history changes.
Workflow
Step 1: Detect the Main Branch
Determine whether the repository uses main or master as its primary branch:
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@'
If that fails (e.g., origin/HEAD is not set), fall back to checking which branch exists locally:
git branch --list main master
Use whichever one exists. If both exist, prefer main. Store the result as $MAIN_BRANCH for subsequent steps.
Step 2: Safety Checks
Run all three checks before proceeding. If any fail, stop and explain the issue to the user.
-
Not on the main branch — The current branch must not be the main branch itself. Squashing the main branch makes no sense and would rewrite shared history.
CURRENT_BRANCH=$(git branch --show-current)If
$CURRENT_BRANCHequals$MAIN_BRANCH, stop with a message: "You are currently on the main branch. Switch to a feature branch first." -
Clean working directory — There must be no uncommitted changes (staged or unstaged). A dirty working tree would mix unrelated changes into the squashed commit.
git status --porcelainIf output is non-empty, stop with a message: "You have uncommitted changes. Please commit or stash them first."
-
Commits exist to squash — The branch must have at least 2 commits ahead of the main branch. With 0 or 1 commits, there's nothing to squash.
MERGE_BASE=$(git merge-base $MAIN_BRANCH HEAD) COMMIT_COUNT=$(git rev-list --count $MERGE_BASE..HEAD)If
$COMMIT_COUNTis 0, stop: "This branch has no commits ahead of $MAIN_BRANCH." If$COMMIT_COUNTis 1, stop: "This branch has only 1 commit — nothing to squash."
Step 3: Show the User What Will Happen
Before making any changes, show the user a summary so they can confirm:
- Current branch name
- Main branch name
- Number of commits that will be squashed
- List of those commits (hash + message)
git log --format="%h %s" $MERGE_BASE..HEAD
Present this as a clear summary, for example:
Branch: feature-login
Squashing 5 commits into 1 (relative to main):
a1b2c3d feat: add login form
d4e5f6g fix: handle empty password
h7i8j9k style: adjust button alignment
l0m1n2o refactor: extract validation logic
p3q4r5s test: add login form tests
Ask the user to confirm before proceeding. This is a destructive operation — once squashed, the original individual commits are gone from the branch history (they can still be recovered via reflog within the git GC window, but that's not something typical users should rely on).
Step 4: Build the Commit Message
Compose a commit message for the squashed commit. The message should be useful and informative:
Title line: Use the first commit's message as the base, or derive a summary from the branch name. If the branch name follows a pattern like feature/login or fix/auth-bug, convert it to a readable title (e.g., "feat: add login functionality").
Body: List all original commit messages as bullet points so the history isn't completely lost:
feat: add login functionality
Squashed commits:
- feat: add login form
- fix: handle empty password
- style: adjust button alignment
- refactor: extract validation logic
- test: add login form tests
Show the proposed commit message to the user and let them confirm or provide a custom message. If the user provides their own message, use that instead.
Step 5: Execute the Squash
git reset --soft $MERGE_BASE
git commit -m "<the commit message>"
git reset --soft moves HEAD back to the fork point while keeping all file changes staged. The subsequent git commit bundles everything into a single commit. The branch name is unchanged — only the commit graph is rewritten.
Step 6: Verify and Inform
After the squash, confirm success:
git log --oneline -5
Show the user the new clean history. Also check whether the branch has been pushed to a remote:
git branch -vv | grep "^\*"
If the branch tracks a remote, remind the user: "This branch has been pushed before. You'll need to force-push to update the remote: git push --force-with-lease". Recommend --force-with-lease over --force because it guards against overwriting someone else's work on the same branch.
Edge Cases
- Detached HEAD — If not on any branch, abort with a clear message.
- Diverged from main — The squash works on commits since the merge-base, so it handles divergence correctly. The merge-base is the most recent common ancestor, not the tip of main.
- Merge commits in the branch —
git reset --softhandles this fine; all changes (including those from merges) end up staged. - Branch has been rebased — If the branch was previously rebased onto main, the merge-base is already up to date and the squash proceeds normally.
04 同仓库更多 Skills
template-skill
Replace with description of the skill and when to use it.
work-weekly-report
Generate structured weekly work summaries from daily work logs. Use when: user provides daily work logs/notes and asks to create a weekly report/summary (周报/周工作总结), or when user pastes fragmented daily entries and wants them consolidated into a categorized summary. Triggers on keywords: 周报, 周工作总结, weekly summary, weekly report, 工作日志整理, 每日日志汇总.
smart-commit
Automated Git commit with Conventional Commits format. Analyzes staged changes, determines commit type and scope, detects description language from commit history (defaults to English), and generates a complete commit message. Use when the user says "commit", "smart commit", "提交代码", "帮我提交", or any variation of requesting a git commit with an auto-generated message.
setup-agents-md
创建、初始化或更新 AGENTS.md 通用工程原则文档时使用。触发词包括“创建 AGENTS.md”、“更新 AGENTS.md”、“初始化 AGENTS.md”、“setup AGENTS.md”、“create AGENTS.md”、“update AGENTS.md”。
resume-screener
Evaluate and grade resumes against job requirements using a 10-level grading system (C, B-, B, B+, A-, A, A+, S, SS, SSS). Provides multi-dimensional scoring with evidence-based reasoning and hiring recommendations. Use when screening candidates, comparing applicants, assessing resume-job fit, or filtering resumes. Supports Chinese and English resumes in any format (PDF, DOCX, text, image).
prompt-optimizer
Transforms vague or simple user prompts into high-quality, structured, and high-performance AI instructions using systematic optimization techniques like XML tagging, few-shot examples, and Chain-of-Thought. Use this skill when you need to improve the reliability, accuracy, or formatting of an AI's output.