本文介绍了恢复合并和历史记录“撤消"来自git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在团队中的正常流程是将要素分支合并到质量检查分支,对该分支进行测试,然后将要素分支移至Master.团队中的某个人正在遵循正常流程,但是在进行质量检查后,他没有将自己的分支机构合并为大师",而是将所有质量检查人员合并为大师".这使我们的主分支搞砸了,因为其他开发人员未进行质量检查的物品进入了分支.

Our normal process on the team is to merge our feature branches into QA branch, test that branch, and then move our feature branch into Master. Someone on the team was following the normal process, but instead of merging his branch into Master after it was QA'd he merged all of QA into Master. This screwed up our main branch as items that were not done being QA'd from other developers entered the branch.

合并是从gitLab的接口而不是终端进行的.我们要做的是完全还原此合并和所有102次提交.还原后,我们不希望有任何历史记录.在我们的遥控器上执行此操作的最佳方法是什么?我见过有人提到将-m与git revert一起使用,但是如果我理解正确,它会弄乱历史记录.合并是否没有真正的撤消"?我们在这里有点绝望.谢谢!

The merge was done from the interface of gitLab and not terminal. What we want to do is completely revert this merge and all 102 commits. We don't want any history of it after the revert. What is the best way to do this on our remote? I've seen people mention using -m with git revert, but if i understand correctly it messes up history. Is there no true "undo" for merges? We're a little desperate here. THanks!

推荐答案

您可以重置 master ,例如

        master
          |
          V
o--o---o--o
          /
         /
o---o---o
        ^
        |
       qa_branch

如果您的存储库看起来像这样

If your repository looks like this you can do

$ git checkout master
$ git reset --hard HEAD^

HEAD ^ HEAD 的第一次父提交的快捷方式.您还可以使用 HEAD ^ 1 .

The HEAD^ is a shortcut for the first parent commit of HEAD. You can also use HEAD^1.

完成此操作后,您的存储库看起来就像

After you did this your repository looks like

     master
       |
       V
o--o---o


o---o---o
        ^
        |
       qa_branch

警告

现在,您必须强制执行覆盖 origin/master 的操作.在这种情况下,您必须确保同时没有其他开发人员将更改推送到 origin/master 之上.否则,这些更改将丢失.

Now you must do a forced push to overwrite the origin/master. In this case you must ensure that no other developer has pushed changes on top of the origin/master in the meanwhile. Otherwise these changes will be lost.

以这种方式进行强制推送

A forced push is done in this way

$ git push -f origin master

这篇关于恢复合并和历史记录“撤消"来自git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 23:58