git:自动特定于行的修复

git: automatic line-specific fixup

我最近了解到 git commit --fixup 它将您的提交标记为较早提交的修复,并在交互式变基期间自动将它们彼此相邻排列。

我怎样才能为多行自动和分别执行此操作?

举个例子。我的 git 历史是这样的:

c5069d5 This commit adds method a() to file A.cpp
ac5db87 This commit does something in file B.cpp
733e2ff This commit adds method b() to file A.cpp
ac5db87 This commit does something else in file B.cpp

并且在我的工作树中,我更改了文件 A.cpp 和 b() 的方法 a() 中的一些行(也许我添加了一个方法 c() )。请注意,我在这里只谈论功能,以便于交流 - 当然,git 不了解编程语言。

是否可以从我在工作树中的两个单独更改自动生成两个单独的修复提交,即:

c5069d5 This commit adds method a() to file A.cpp
a5559d5 fixup! This commit adds method a() to file A.cpp
ac5db87 This commit does something in file B.cpp
733e2ff This commit adds method b() to file A.cpp
a53aad5 fixup! This commit adds method b() to file A.cpp
ac5db87 This commit does something else in file B.cpp

(现在工作树包含 A.cpp 中的更改,其中添加了 c()) 如果这适用于工作树中的多个文件(而不是像本例中那样只有单个 A.cpp)

,那就太好了

更新,替代措辞:

git-blame 向我显示每行的最后一次提交。如果我现在更改一行,我想修复提交 git-blame 之前向我展示了这一行。

正如 jberrymann 在回答中所建议的那样,https://github.com/keis/git-fixup 正是这样做的。使用命令 git fixup -c 为您提供可能的修复目标列表