当然你可以恢复
git revert <SHA of erroneous commit>
或者,您可以重写完整的历史记录,但这将更新所有可能危险的 SHA(如果其他人已经在分支上工作)
为此,您必须冻结其他开发人员才能在此期间工作
git checkout branchA // one of the problematic branch
git rebase -i <sha1 befor the pb>
--> mark the "remove ignored file" commit as `edit`
// this will stop into the "guilty commit"
// at this point we undo the commit
git reset HEAD^
// and then redo do the job like it should have
....
// including the "git commit "
// you can even do more than one git "commit"
git rebase --continue
// then
git push -f origin branchA
其他开发人员现在可以再次拉动
注意:为了更安全地执行此操作,您可以创建一个工作分支并在结果不符合预期时将其删除
git checkout branchA // one of the problematic branch
git checkout -b branchA-before-rework // just in case
git checkout -b A-rework-1
git revert <SHA1 erroneous commit>
// ? happy :)
git branch -f branchA // will force branchA to here
git push -f origin branchA
// not happy try something else
git checkout branchA // one of the problematic branch
git checkout -b A-rework-2
// do above "git rebase -i" stuff EXCEPT push -f
// ? not happy drop it
git checkout branchA // one of the problematic branch
git checkout -b A-rework-n
// ? happy :)
git branch -f branchA // will force branchA to here
git push -f origin branchA