简体   繁体   English

git rebase master错误地执行git pull而不是git push origin / your_branch -f后

[英]After a git rebase master mistakenly executed git pull instead of git push origin/your_branch -f

Probably due to lack of sleep instead of executing a force push after a git rebase master I've executed a git pull . 可能是由于缺乏睡眠而不是在git rebase master之后执行强制推送,我执行了git pull Now my pull request is messed up including all the commits from master. 现在我的拉取请求被弄乱了,包括来自master的所有提交。 Any suggestion to revert this? 有什么建议可以还原吗?

git reflog has come to the rescue for me on multiple occasions. git reflog已多次为我提供帮助。

This reference log records updates to your local repository/branches/references. 此参考日志记录对本地存储库/分支/参考的更新。

So if you find the head commit of the desired branch directly before the pull in this case, you can reset your current branch to that reference. 因此,在这种情况下,如果在拉动之前找到所需分支的起始提交,则可以将当前分支重置为该引用。 For example to reset to HEAD@{2} 例如,重置为HEAD@{2}

git reset --hard HEAD@{2}

Note: be absolutely sure about your action before using --hard 注意:使用--hard之前,请务必确定您的操作

Git reflog documentation Git reflog文档

Running git pull is just a fetch followed by a merge of the upstream branch. 运行git pull只是获取,然后合并上游分支。 Assuming the merge succeeded and you still have this branch checked out, something like this should fix it: 假设合并成功,并且您仍然将该分支检出,则应使用以下方法解决此问题:

$ git reset @^1

That resets the branch to the first parent which should be the rebased branch (the second parent being the head of the old upstream version of the branch.) You can verify before doing the reset: 这会将分支重置为第一个父级,该父级应该是经过重新设置的分支(第二个父级是该分支的旧上游版本的头部。)您可以在进行重置之前进行验证:

$ git log --graph @^1

or 要么

$ gitk @^1

If those look sane, then the reset should do it. 如果这些看起来理智,则重置应执行此操作。 It will not touch the files in your work tree so you can see if this resulted in any surprising changes. 它不会触摸工作树中的文件,因此您可以查看是否导致任何令人惊讶的更改。 I suspect there will be none as the merge was probably a no-op as far as the code is concerned (again, assuming it succeeded.) 我怀疑不会有任何合并,因为就代码而言,合并可能是无操作的操作(再次假设成功)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM