Git:拉错了分支,然后推动合并。如何撤销?

Git:拉错了分支,然后推动合并。如何撤销?,git,version-control,branch,branching-and-merging,git-workflow,Git,Version Control,Branch,Branching And Merging,Git Workflow,我最近在git合并策略上犯了一个错误,直到我继续工作并做出更多的提交,我才注意到结果错误。为了简洁起见,假设我有两个分支,hotfix和new\u feature。我做了如下的事情: git checkout new_feature git commit -m "Commit to the feature branch" git checkout hotfix git pull origin new_feature # Uh oh, I pulled the wrong branch! git

我最近在git合并策略上犯了一个错误,直到我继续工作并做出更多的提交,我才注意到结果错误。为了简洁起见,假设我有两个分支,
hotfix
new\u feature
。我做了如下的事情:

git checkout new_feature
git commit -m "Commit to the feature branch"
git checkout hotfix
git pull origin new_feature # Uh oh, I pulled the wrong branch!
git commit -m "Commit to the hotfix"
git push origin hotfix # Uh Oh, pushed the bad merge!
在上述事件之后,其他开发人员也向热修复程序分支提交了承诺。现在,我们有一个修补程序,我们想推出,但不能,因为它包含的功能工作尚未完成

关于这种情况,我看到过很多类似的问题,但没有一个是100%匹配的(大多数问题都涉及在错误拉取之后直接撤消提交,而不是先推)。我更进一步了,而且真的把事情搞糟了

有关于我如何补救这一问题的分步指南吗

谢谢

编辑:许多其他答案提到了
git reflog
,因此这里是我的一份修改副本。我已经更改了哈希和分支名称,以匹配上面的示例

aaaaaaa HEAD@{0}: checkout: moving from new_feature to hotfix
bbbbbbb HEAD@{1}: checkout: moving from hotfix to new_feature
aaaaaaa HEAD@{2}: commit: Added analytics tracking
ccccccc HEAD@{3}: commit (merge): Fixed a merge issue in compiled css # BAD MERGE?
ddddddd HEAD@{4}: checkout: moving from new_feature to hotfix
eeeeeee HEAD@{5}: commit: Finished updating the events for the header
ddddddd HEAD@{6}: checkout: moving from hotfix to new_feature
ddddddd HEAD@{7}: checkout: moving from new_feature to hotfix

在上面的reflog中,
HEAD@{3}
看起来是错误的合并。我在
hotfix
分支上,拉入了
new_feature
分支,该分支给出了合并冲突。我修复了它们,并按下。我该怎么做才能修复这个问题?

找到提交哈希:
git log--pretty=format:“%h%s”| grep“提交到hotfix”


还原“Uh-oh”提交:
git Revert 15d2e1f-m2

但并不是只有一次提交。“Uh-oh”提交是来自另一个分支的合并,其中包括一组提交!我需要查看热修复历史记录并还原一组提交,这似乎有点“黑客”