[英]Git - Revert Large commit history from Pushed Head to wrong branch
A colleague of mine somehow pushed his HEAD revision of a release branch my team is working on to our main development branch. 我的一位同事以某种方式将他对我们团队正在开发的发行分支的HEAD修订推到了我们的主要开发分支。 (This would be 145 commits improperly pushed) (这将是不正确地推送145次提交)
I want to keep our commit history clean so I am toying with the idea if I should do anything, or just create a new Development branch to begin working on. 我想保持提交历史记录的整洁,因此我想选择是否做任何事情,或者只是创建一个新的Development分支来开始工作。
I cannot simply do a 我不能简单地做一个
git revert <last-trusted-sha>..HEAD
Because there are multiple merges on the branch (From when we do a pull request and Git creates a merge remote_currentbranch to currentbranch). 因为分支上有多个合并(从我们执行拉取请求到Git创建从remote_currentbranch到currentbranch的合并)。
Is there any way to resolve this easily? 有什么办法可以轻松解决此问题? Or do I just go commit by commit until it is corrected? 还是我只是逐个提交直到更正?
Thanks 谢谢
To recover development
branch, you can use below commands: 要恢复development
分支,可以使用以下命令:
git checkout development
git reset --hard HEAD~145
git push -f
Or if you know the last commit sha-1 value on the development
branch before commits on the release
branch were pushed to the development
branch, you can also use git reset --hard <last commit>
to replace the command git reset --hard HEAD~145
. 或者,如果你知道上次上提交的SHA-1值development
分支之前提交的release
分支都推到了development
分支,你也可以使用git reset --hard <last commit>
替换命令git reset --hard HEAD~145
Then the development
branch would be recovered. 然后将恢复development
分支。
This should be quite easy to fix technically: 从技术上来说,这应该很容易解决:
git branch develop THEHASH -f
git push origin develop -f
Normally you would not do something like this out of respect for your colleagues. 通常,出于对同事的尊重,您不会这样做。 But in this case, everything is broken anyways already, so you might as well. 但是在这种情况下,一切都已经被破坏了,所以您也应该这样做。
To find the correct commit 145 steps back, git reflog
might be of help, unless you can spot it easily using git log
. 要找到正确的提交145个步骤,除非您可以使用git log
轻松发现它,否则git reflog
可能会有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.