gfix 代码创建
- 作者仓库星标 2,380
- 许可证 MIT
- 作者仓库 dotfiles
gfix — Amend a Past Commit
Use the gfix shell command to fold staged changes into a commit that is not the most recent. This is the preferred way to amend historical commits in this repo.
How gfix works
Source: ~/code/dotfiles/plugins/git.zsh (the gfix function)
gfix [-m <message>] <commit-sha> does the following:
- Guards against running during an in-progress git operation (rebase, merge, cherry-pick, etc.)
- Stashes any unstaged changes (preserving the index)
- Creates a fixup commit from whatever is currently staged:
- With no
-m:git commit --fixup <commit-sha>(content-only fixup) - With
-m <message>: creates a manualamend!commit with subjectamend! <original-subject>and body<message>, which autosquash then folds into the target (replacing its message, and including any staged changes;--allow-emptyis used if nothing is staged)
- With no
- Runs
GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash <commit-sha>^to automatically squash the fixup into the target commit - Restores any stashed unstaged changes
When to use gfix
Use gfix when you need to amend a commit that is not the HEAD commit. For example:
- A review comment asks for a change to code introduced 3 commits ago
- You notice a typo or bug in an earlier commit while working on something else
- You want to keep a clean, logical commit history where each commit is self-contained
If you only need to amend the most recent commit, use git commit --amend instead.
Steps
Determine the safe range — The target commit must be within the current branch's own commits, not on or before the base branch. Use
detect_base_branchto find the base branch. As a last resort, ask the user.The target commit must appear in
git log --oneline <base-branch>..HEAD. If it does not, stop and tell the user — rewriting shared history would cause problems.Identify the target commit — Use
$ARGUMENTSto understand what the user wants fixed. List the safe commits withgit log --oneline <base-branch>..HEADand examine their diffs to find the commit that introduced the code the user wants changed.Make and stage the changes — Edit the files, then
git addonly the files that belong to the target commit.Run gfix — Pass the target commit SHA. Add
-m <message>to also rewrite the target commit's message:gfix <commit-sha> gfix -m "new commit message" <commit-sha>Handle rebase conflicts — If the rebase hits conflicts:
- Read the conflicting files and resolve them
git addthe resolved filesgit rebase --continue- Repeat until the rebase finishes
Verify — Run
git log --oneline -10to confirm the history looks correct. If relevant tests exist, run them.
- 流狐分类
- 工程开发
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @ryanb · MIT
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 需简单配置
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Source: ~/code/dotfiles/plugins/git.zsh (the gfix function) gfix [-m <message>] <commit-sha> does the following: Guards against running during an in-progress git operation (rebase, merge, cherry-pick, etc.)
Use gfix when you need to amend a commit that is not the HEAD commit. For example: A review comment asks for a change to code introduced 3 commits ago You notice a typo or bug in an earlier commit while working on something else
Determine the safe range — The target commit must be within the current branch's own commits, not on or before the base branch. Use detectbasebranch to find the base branch. As a last resort, ask the user. The target commit must appear in git log --oneline…
# gfix — Amend a Past Commit
Use the `gfix` shell command to fold staged changes into a commit that is not the most recent. This is the preferred way to amend historical commits in this repo.
## How gfix works
Source: `~/code/dotfiles/plugins/git.zsh` (the `gfix` function)
`gfix [-m <message>] <commit-sha>` does the following:
1. Guards against running during an in-progress git operation (rebase, merge, cherry-pick, etc.)
2. Stashes any unstaged changes (preserving the index)
3. Creates a fixup commit from whatever is currently staged:
- With no `-m`: `git commit --fixup <commit-sha>` (content-only fixup)
- With `-m <message>`: creates a manual `amend!` commit with subject `amend! <original-subject>` and body `<message>`, which autosquash then folds into the target (replacing its message, and including any staged changes; `--allow-empty` is used if nothing is staged)
4. Runs `GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash <commit-sha>^` to automatically squash the fixup into the target commit
5. Restores any stashed unstaged changes
## When to use gfix
Use gfix when you need to amend a commit that is **not** the HEAD commit. For example:
- A review comment asks for a change to code introduced 3 commits ago
- You notice a typo or bug in an earlier commit while working on something else
- You want to keep a clean, logical commit history where each commit is self-contained
If you only need to amend the most recent commit, use `git commit --amend` instead.
## Steps
1. **Determine the safe range** — The target commit must be within the current branch's own commits, not on or before the base branch. Use `detect_base_branch` to find the base branch. As a last resort, ask the user.
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> How gfix works → When to use gfix → Steps
要点 -> not · Determine the safe range · must · stop and tell the user · Identify the target commit · Make and stage the changes · Run gfix · Handle rebase conflicts
文件/命令 -> gfix · ~/code/dotfiles/plugins/git.zsh · gfix [-m <message>] <commit-sha> · git commit --fixup <commit-sha> · -m <message> · amend! · amend! <original-subject> · <message>
内容 SHA-256 -> 61a1eecc2a41
方法与流程
适用与边界
原文中的明确线索
gfix、~/code/dotfiles/plugins/git.zsh、gfix [-m <message>] <commit-sha>、git commit --fixup <commit-sha>、-m <message>、amend!、amend! <original-subject>、<message>