拆分 Git 提交
Splitting a Git Commit

原始链接: https://blog.gnoack.org/post/git-history-split

拆分 Git 提交 索引 | 关于 2026-08-12 现在拆分 Git 提交变得简单了,只需使用: git history split ${REF} 它会逐个代码块地询问你希望包含在第一个提交中的内容,然后弹出编辑器让你填写第一次和第二次提交的信息。没有比这更简单的了。 附注:关于拆分提交的 Stack Overflow 问题讨论的是那种陈旧且繁琐的方法。虽然第 20 个回答提供了正确的方法,但截至今日仅获得了 2 个赞,而那个使用繁琐方法的旧版置顶回答却有 2656 个赞。

Hacker News 上的讨论集中在 Git 2.54 版本中引入的实验性功能 `git history split` 命令上,该功能旨在简化提交拆分流程。 虽然一些用户称赞这一新工具是迟来的改进,但也有人认为原文对“交互式变基”(interactive rebase)的批评过于苛刻,毕竟后者对大多数开发者而言仍是标准且可靠的方法。批评者指出,`git history` 目前非常新,尚未在标准操作系统发行版中广泛使用,因此对许多团队来说尚不实用。 辩论的重要部分突显了 Jujutsu (jj) 和 GitButler 等现代 Git 相关工具的持续影响。许多参与者承认,与这些优先考虑用户体验的新工具相比,传统的 Git 命令行操作往往显得“繁琐”。一些资深用户强调,尽管 `git history split` 是一个受欢迎的补充,但熟练掌握 `git rebase -i` 结合 `git add -p` 仍然是一项至关重要且极其灵活的技能。讨论还涉及了旧版 Stack Overflow 答案的过时问题,以及在不同操作系统上维护现代 Git 版本所面临的持续困难。
相关文章

原文
Splitting a git commit

Splitting a git commit is now easy, using:

git history split ${REF}

It will ask you hunk by hunk for the things to include in the first commit, and then bring up the editor for the first and second commit message. It couldn’t be simpler than that.

P.S. The stack overflow question for splitting commits discusses the old and cumbersome approach. The 20th answer discusses the right approach but has a meagre 2 upvotes as of today, compared to 2656 for the older top answer with the cumbersome approach.

联系我们 contact @ memedata.com