Git 我犯了三次罪。如何仅删除第二次提交?
比如说Git 我犯了三次罪。如何仅删除第二次提交?,git,github,commit,Git,Github,Commit,比如说 第一次提交时,文件代码为: first commit. 第二次提交时,文件代码为: first commit. second commit. first commit. second commit. third commit. 第三次提交时,文件代码为: first commit. second commit. first commit. second commit. third commit. 如何使用git仅删除第二次提交? 文件代码显示: first commit
first commit.
first commit.
second commit.
first commit.
second commit.
third commit.
first commit.
second commit.
first commit.
second commit.
third commit.
first commit.
third commit.
交互式重基可以使这更容易:
git rebase -i HEAD^^
将打开一个编辑器,显示最后两次提交。您应该删除包含您不想要的提交的行(顶行),保存文件,然后退出编辑器
Git随后将尝试应用第三次提交,而不应用第二次提交。无论如何,这将失败。如果是这样,您需要编辑文件,使其看起来像您想要的那样,然后按如下方式完成重设基础过程:
git add .
git rebase --continue
如果你陷入可怕的混乱
git rebase --abort