我承诺三遍。如何仅删除第二个提交?

I commit three times. How can I delete the second commit only?

例如。

  1. 第一次提交,文件代码为:

    first commit. 
    
  2. 第二次提交,文件代码为:

    first commit.
    second commit.
    
  3. 第三次提交,文件代码为:

    first commit.
    second commit.
    third commit.
    

如何使用 git 仅删除第二个提交? 文件代码显示:

first commit.
third commit.

交互式变基可以使这更容易:

git rebase -i HEAD^^

将打开一个编辑器,显示最后两次提交。您应该删除包含您不想要的提交的行(顶行),保存文件,然后退出编辑器。

Git 将尝试应用第三次提交而不是第二次提交。就像这不会失败一样。如果是这样,您需要编辑文件,使它们看起来像您想要的那样,然后像这样完成变基过程:

git add .
git rebase --continue

如果你陷入可怕的混乱中....

git rebase --abort