Skill站外收录 @skilllib/skill-2117939930272417554
squashman
根据代码变更的上下文自动拆分补丁,将修改归类到最相关的先前提交,生成符合自动合并规则的修复提交,优化提交历史的逻辑连贯性与可追溯性。
开发运维 AI 技能
Skills.MD
# Git Smart Fixup
## Trigger
User invokes `/smart-fixup` or asks to split changes into fixup commits.
## Arguments
- `--from-head`: Use the HEAD commit instead of staged changes (will reset HEAD and recreate as fixups)
- `--dry-run`: Show what fixup commits would be created without actually creating them
- `--base <ref>`: Specify the base branch (default: auto-detect master/main)
## Instructions
### Step 1: Determine the Base Branch and Commit Range
1. Find the merge base between current branch and main/master:
```bash
git merge-base HEAD master
```
2. Get the list of commits from merge base to HEAD (these are candidates for fixup targets):
```bash
git log --oneline --reverse <merge-base>..HEAD
```
3. Store commit hashes and their messages for later matching.
### Step 2: Get the Changes to Split
**If using staged changes (default):**
```bash
git diff --cached --unified=0
```
**If using `--from-head`:**
```bash
# Get the diff from HEAD commit
git show HEAD --unified=0 --format=""
# Store HEAD message for potential fallback
git log -1 --format="%s" HEAD
# Soft reset to unstage HEAD's changes
git reset --soft HEAD~1
```
### Step 3: Analyze Each Hunk and Find Target Commits
For each changed file and hunk:
1. Parse the diff to extract file paths and line ranges.
2. For each modified/deleted line range, use git blame to find which commit last touched those lines:
```bash
# For the version before our changes, blame the lines being modified
git blame -l -L <start>,<end> <merge-base>..HEAD~1 -- <file> 2>/dev/null
```
If blaming the range fails (new lines), check the surrounding context:
```bash
git blame -l -L <start-3>,<start> HEAD~1 -- <file> 2>/dev/null
```
3. For each hunk, determine the target commit:
- Extract commit hashes from blame output
- Check if any blamed commit is within our branch's commits (between merge-base and HEAD)
- If multiple commits touched the lines, prefer the most recent one in our branch
- If no branch commit is found, this hunk will go into a "new" commit
### Step 4: Group Changes by Target Commit
Create a mapping of target commits to their associated hunks:
```
{
"<commit-hash-1>": [hunk1, hunk2, ...],
"<commit-hash-2>": [hunk3, ...],
"NEW": [hunk4, hunk5, ...] // Changes not attributable to any branch commit
}
```
### Step 5: Create Fixup Commits
For each target commit with associated hunks:
1. Stage only the relevant hunks using `git add -p` or by creating patch files:
```bash
# Create a patch for this group of hunks
# Apply with: git apply --cached <patch-file>
```
2. Create the fixup commit:
```bash
git commit --fixup=<target-commit-hash>
```
3. For changes marked as "NEW" (not attributable to branch commits):
- If `--from-head` was used, use the original HEAD commit message
- Otherwise, prompt the user for a commit message or create with a descriptive message
### Step 6: Report Results
Display a summary:
```
Original commit: <original-head>
Created X fixup commits:
fixup! <original-commit-message-1> (N files, M lines)
fixup! <original-commit-message-2> (N files, M lines)
Remaining changes (not matched to branch commits):
<new-commit-message> (N files, M lines)
To confirm that these commits match the original state, run:
git diff <original-head>..<new-head>
To squash these fixups, run:
git rebase -i --autosquash <merge-base>
```
## Edge Cases
1. **No staged changes and no `--from-head`**: Error with helpful message.
2. **New files**: These typically become a new commit unless the user added them alongside modifications to existing code.
3. **Binary files**: Skip blame analysis, treat as new changes.
4. **Renamed files**: Use `git log --follow` to track through renames.
## Implementation Notes
- Use `git diff --cached -U0` for minimal context when parsing hunks
- Parse unified diff format: `@@ -start,count +start,count @@`
- Handle the case where blame returns commits outside the branch range
- Consider using `git log -S` or `git log -G` as fallback for finding related commits
- Preserve the order of fixup commits to match the original commit order for cleaner rebases
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「squashman」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次