Re-doing a reverted merge in Git

前端 未结 8 2175
一个人的身影
一个人的身影 2020-11-22 11:10

I have run into a bit of a problem here: I had a problem-specific branch 28s in Git, that I merged in the general develop branch. Turns out I had d

8条回答
  •  旧时难觅i
    2020-11-22 11:43

    Instead of using git-revert you could have used this command in the devel branch to throw away (undo) the wrong merge commit (instead of just reverting it).

    git checkout devel
    git reset --hard COMMIT_BEFORE_WRONG_MERGE
    

    This will also adjust the contents of the working directory accordingly. Be careful:

    • Save your changes in the develop branch (since the wrong merge) because they too will be erased by the git-reset. All commits after the one you specify as the git reset argument will be gone!
    • Also, don't do this if your changes were already pulled from other repositories because the reset will rewrite history.

    I recommend to study the git-reset man-page carefully before trying this.

    Now, after the reset you can re-apply your changes in devel and then do

    git checkout devel
    git merge 28s
    

    This will be a real merge from 28s into devel like the initial one (which is now erased from git's history).

提交回复
热议问题