在 git 推送之后,从特定提交中取消单行的一部分

Cancel part of a single line from specific commit, after git push

有人将以下行推送到我们的存储库:

git = ['a', 'w', 'e', 's', 'o', 'm', 'e', BugSyntaxErrorBug]

但实际上应该是:

git = ['a', 'w', 'e', 's', 'o', 'm', 'e']

由于推送了很多次,我想从这次推送中重写它。这背后的想法是,如果有人将提取此代码的旧版本,则该代码将起作用。

谢谢:)

我就是这样做的。

标记这些,以便在出现问题时可以恢复。

git tag MyOldCommit BADCOMMIT
git tag MyOldMaster master

如果需要,您可以使用

恢复 master 不变
git branch -f master MyOldMaster

现在检查错误提交到新分支

git checkout -b MyFixedCommit BADCOMMIT

删除有问题的字节后,用新提交替换旧提交。

git commit --amend -m"my commit message"

回到你原来的分支master分支

git checkout master

rebase master(而且只有 master!!!)到 MyFixedCommit

git rebase --onto MyFixedCommit BADCOMMIT master

git 将重新播放(通过提交提交)从 BADCOMMIT 到 tip of master 到 MyfixedCommit 的更改。您必须解决 Git 在途中发现的任何冲突。

!!由于您正在重写历史记录,因此 master 的提交链现在将与引用旧 master 提交链的其他用户的标签和分支不同!