Revert Merge and history "undo" from git

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.

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!


You can reset the master , eg

        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^

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

Warning

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

I believe the best solution is to create a new branch from the last good point of your master branch (eg, tmp-master ), and then delete the master branch entirely. Once it's gone, you can create a new master from the head of your tmp-master branch. Of course, you'll then need to force the new master branch up to the origin and get everyone else with a copy of master to pull it down again.

I believe the commands should be:

git checkout master
git checkout <sha of last good commit>
git checkout -b tmp-master
git branch -d master
git checkout -b master
git push -f origin master

then, on each machine which has the master branch:

git checkout master
git pull

For a similar (but slightly different) approach, check out: this question


We don't want any history of it after the revert.

In that case, this is likely a WONTFIX for GitLab as they are generally against history change from the web UI. Eg http://feedback.gitlab.com/forums/176466-general/suggestions/5590144-allow-git-reset-hard-from-web-interface:

You should not reset branches on the remote repo.

So you will probably have to resort to non-GitLab Git methods which can be found on the other answers, and many other Git questions.

链接地址: http://www.djcxy.com/p/15830.html

上一篇: Redmine Git repo在分支重命名后不同步

下一篇: 从git中还原合并和历史“撤销”