简体   繁体   English

撤消git merge(尚未推送)

[英]Undo a git merge (hasn't been pushed yet)

I just committed some changes into one of my feature branches ("feedback_tab") then, checked out "master" and merged them in there. 我刚刚对我的一个功能分支(“feedback_tab”)进行了一些更改,然后检出“master”并将它们合并到那里。 I actually meant to merge them into my "development" branch. 我实际上是想将它们合并到我的“开发”分支中。

Now, master is ahead of 'origin/master' (its remote) by 17 commits - I haven't pushed the merge up (and don't want to, obviously). 现在,master通过17次提交领先于'origin / master'(它的远程) - 我没有推动合并(显然不希望)。 How can I revert master back to the same state as before the accidental merge? 如何将master恢复到意外合并之前的状态? I'm confused between git revert and git reset with this stuff. 我对git revertgit reset与这些东西感到困惑。

I looked in my git log and there's no entry for merging feedback_tab into master. 我查看了我的git日志,并没有将feedback_tab合并到master中的条目。 I'd have thought it would be the top entry? 我原本以为它会成为最佳入场券?

Bit confused :/ any help welcome! 有点困惑:/任何帮助欢迎! max 最大

To undo a merge that was NOT pushed: 要撤消未推送的合并:

git reset --merge ORIG_HEAD

If during the merge you get a conflict, the best way to undo the merge is: 如果在合并期间出现冲突,则撤消合并的最佳方法是:

git merge --abort

git reset --hard HEAD~17 takes you back 17 commits ahead of the head of master. git reset --hard HEAD~17在主人头之前带你回17次提交。 git rebase -i HEAD~17 probably gets rid of the extra commits as well. git rebase -i HEAD~17可能也会删除额外的提交。

Taken from git reset 取自git reset

Undo a merge or pull

    $ git pull                         <1>
    Auto-merging nitfol
    CONFLICT (content): Merge conflict in nitfol
    Automatic merge failed; fix conflicts and then commit the result.
    $ git reset --hard                 <2>
    $ git pull . topic/branch          <3>
    Updating from 41223... to 13134...
    Fast-forward
    $ git reset --hard ORIG_HEAD       <4>

This one will surely work! 这一定肯定会奏效!

git reset --hard HEAD~1 
git init

The first one will revert the changes you recently made (the merge) the second will init the repo to latest (therefore will fast forward to latest on origin) 第一个将恢复您最近进行的更改(合并),第二个将初始化回购(因此将快进到最新的原点)

I've tried 我试过了

git reset --merge

but it didn't do the trick. 但它没有做到这一点。

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

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