Best way to recover after creating branch from wrong branch and merging

I realize that there have been similar questions posted about this subject; I'm afraid I'm not grasping the best way to recover from this situation. I'm using SourceTree on Windows.

I branched from dev, made some commits to a handful of files, pushed to the remote, and merged back into dev. It turns out that there are many pre-existing commits in dev that are not going to be ready to be promoted to master any time soon, and I really should have branched from master instead.

So I made a new branch from master, and I then cherry-picked the commits from the original branch which I know are good. One wrinkle is that two of the files that I originally modified will have different changes in the new branch.

However, I'm unsure as to best handle the process of resetting the dev branch back to the state it was in prior to the two merges that I made. Should I:

  • Check out the first branch, hard reset it to the point where it was originally branched, commit those changes, push to remote, and merge?
  • Or, check out the first branch, Log Selected on each affected file, reset each file to the prior commit, commit all changes, push, merge?
  • Or something else?
  • Here's the graph. The left-most branch is the original branch from dev. The next branch is the new branch from master, with cherry-picked commits. The blue line is the commit that I want to reset dev back to. Thanks! 在这里输入图像描述


    鉴于NO ONE已经从远程develop分支中撤出,所有你需要做的就是覆盖分支develop所指向的内容,并遵循这些命令来做到这一点:

    # Change your local develop to point that old version of that branch 
    git checkout -B develop <commit-hash-of-blue-line-in-pic>
    # FORCE push your local develop to the remote develop
    git push origin -f develop
    
    链接地址: http://www.djcxy.com/p/49842.html

    上一篇: 停止在git中使用一系列提交

    下一篇: 从错误的分支和合并中创建分支后恢复的最佳方法