Git rebase : fixup multiple commits with one commit

标签 git git-rebase

假设我有一个 git 分支,在共享它之前的最后审查中,我发现了一些小错误,例如拼写错误。我想做的是将那个补丁应用为“修复”,但它实际上会影响许多提交,因此在最终历史记录中没有错误的迹象。

也就是说,如果我在一次提交中更改 A 行,然后在另一次提交中更改 B 行,然后我有一个影响 A 行和 B 行的补丁,我想在提交更改 A 行的地方做一个 rebase 由该补丁的 A 部分修复,提交更改行 B 获取 B 部分,而无需手动确定哪些提交。有没有简单的方法可以做到这一点?

我认为伪代码脚本应该是这样的:

collect all hunks from the fixup
for commit in the history we are rebasing:
    check out commit
    for hunk in fixups:
        try:
            apply hunk to the working tree
        except:
            continue
        remove hunk from fixups
    commit the working tree.

最佳答案

git rebase --autosquash 似乎提供了大部分功能:如果您有一个以 fixup! 开头的提交,那么 git rebase --autosquash 将重新排序该提交并使其成为修复,将其 merge 。

此外,这似乎提供了我所询问的其余功能!:https://github.com/torbiak/git-autofixup

使用 git autofixup,它会获取您的工作更改,找到它的哪些部分与哪些部分相符,并​​可能使多个 fixup! 自动提交。所以……

  1. 进行修复更改。
  2. 运行 git autofixup master,它会接受工作更改并使一个或多个 fixup! 自动提交。
  3. 最后执行 git rebase --autosquash master 并且 fixup! 提交将被重新排序到位。

关于Git rebase : fixup multiple commits with one commit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19733375/

相关文章:

git - 如何运行 git rebase 交互模式来删除重复提交

git - 使用 git,如何在父远程分支 rebase 后保存主题分支?

Git:如何分析具有多文件历史记录的代码?

Git 显示文件的最后更改

git - 如何通过github API在github中创建仓库?

svn - 在颠覆中使用 git

git - 撤消 git pull --rebase

git - 有谁知道用于 windows 的 git bash 程序用于其 shell 的是什么?

陈旧分支的 git merge 或 rebase?

git - 同时管理多个 pull 请求