git-hunk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/git-hunk - split changes into focused commits
/git-hunk - 将改动拆分为聚焦的提交
Requires: (or )
uv tool install git-hunkpip install git-hunk依赖要求:(或)
uv tool install git-hunkpip install git-hunkWorkflow
工作流程
- — see all hunks (file, id, +/- stats). No diffs.
git-hunk list - or
git-hunk show <id> [<id>...]when headers aren't clear enough.git-hunk show --all - Plan commits before staging. For each planned commit, list the hunk IDs (and line ranges for partial hunks). A single hunk may need to be split across commits. Ask the user if grouping is ambiguous.
-l - Stage and commit each group:
bash
git-hunk stage <id1> <id2> ... git commit -m "<type>: <description>" - again to check nothing got left behind.
git-hunk list
- —— 查看所有hunk(文件、ID、增减量统计),不展示diff内容。
git-hunk list - 当标题信息不够清晰时,使用或
git-hunk show <id> [<id>...]。git-hunk show --all - 暂存前先规划提交内容。针对每个规划的提交,列出对应的hunk ID(部分hunk可使用指定行范围)。单个hunk可能需要拆分到多个提交中,如果分组存在歧义请询问用户。
-l - 暂存并提交每个分组:
bash
git-hunk stage <id1> <id2> ... git commit -m "<type>: <description>" - 再次执行检查是否有遗漏的改动。
git-hunk list
Partial hunks
部分hunk操作
Line selection () works with , , and (requires single id):
-lstageunstagediscard- Include lines:
git-hunk stage <id> -l 3,5-7 - Exclude lines:
git-hunk stage <id> -l ^3,^5-7
行选择参数()可用于、和命令(需要指定单个ID):
-lstageunstagediscard- 包含指定行:
git-hunk stage <id> -l 3,5-7 - 排除指定行:
git-hunk stage <id> -l ^3,^5-7
Fixing mistakes
错误修正
- — move staged hunks back to working tree.
git-hunk unstage <id1> <id2> ... - — partially unstage specific lines.
git-hunk unstage <id> -l 3,5-7 - — permanently discard unstaged hunks (restore from HEAD).
git-hunk discard <id1> <id2> ... - — partially discard specific lines.
git-hunk discard <id> -l 3,5-7
- —— 将已暂存的hunk移回工作区。
git-hunk unstage <id1> <id2> ... - —— 部分取消暂存指定行的改动。
git-hunk unstage <id> -l 3,5-7 - —— 永久丢弃未暂存的hunk(从HEAD恢复内容)。
git-hunk discard <id1> <id2> ... - —— 部分丢弃指定行的改动。
git-hunk discard <id> -l 3,5-7
Example git-hunk list
output
git-hunk listgit-hunk list
输出示例
git-hunk listunstaged:
labelme/app.py
c43213b @@ -78,6 +78,7 @@ _AI_CREATE_MODES +1
4da0d77 @@ -1364,6 +1365,19 @@ class MainWindow +13
labelme/translate/de_DE.qm
7a3befc Binary fileunstaged:
labelme/app.py
c43213b @@ -78,6 +78,7 @@ _AI_CREATE_MODES +1
4da0d77 @@ -1364,6 +1365,19 @@ class MainWindow +13
labelme/translate/de_DE.qm
7a3befc Binary fileNotes
注意事项
- IDs are content-based hashes, stable across partial staging, and support prefix matching
- — filter hunks by file path
git-hunk list [<file>...] - /
--stagedto filter--unstagedandlist(both search staged+unstaged by default)show - exists but plain output is usually enough
--json - One logical change per commit, conventional commit messages
- ID是基于内容生成的哈希值,在部分暂存操作中保持稳定,支持前缀匹配
- —— 按文件路径过滤hunk
git-hunk list [<file>...] - 可使用/
--staged过滤--unstaged和list命令的结果(默认同时搜索暂存和未暂存内容)show - 支持参数,但普通文本输出通常已满足需求
--json - 每个提交对应一项逻辑改动,使用约定式提交信息