git:自动行特定的修复

时间:2015-12-02 15:35:32

标签: git git-rebase git-interactive-rebase

我最近了解了git commit --fixup,它将您的提交标记为早期提交的修正,并在交互式rebase期间自动将它们排列在一起。

如何自动分开多行?

采用以下示例。我的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和a()的方法b()中的一些行(也许我添加了方法c())。请注意,我这里只讨论函数以使通信更容易 - 当然,git不知道编程语言。

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

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。

1 个答案:

答案 0 :(得分:0)

正如jberrymann的回答所建议的,https://github.com/keis/git-fixup确实做到了这一点。使用命令delete from mytable T left join (select count(*) cnt, Name, Animal from mytable group by Name, Animal) X on t.Name = X.Name and t.Animal = X.Animal where cnt>1 为您提供了可能的修复目标的列表