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 done it too fast, so I used git-revert to undo the merge. Now, however, the time has come to merge 28s into develop, but git-merge command sees the original merge, and happily announces that all is well and branches have been already merged. What do I do now? Create a 'Revert "Revert "28s -> develop"" ' commit? Doesn't seem to be a good way to do it, but I can't imagine any other at the moment.

树的结构是什么样子的:


当前回答

我建议您按照以下步骤恢复一个恢复,比如SHA1。

git checkout develop #go to develop branch
git pull             #get the latest from remote/develop branch
git branch users/yourname/revertOfSHA1 #having HEAD referring to develop
git checkout users/yourname/revertOfSHA1 #checkout the newly created branch
git log --oneline --graph --decorate #find the SHA of the revert in the history, say SHA1
git revert SHA1
git push --set-upstream origin users/yourname/revertOfSHA1 #push the changes to remote

现在为分支用户/yourname/revertOfSHA1创建PR

其他回答

在最初的合并之前在提交时创建新的分支-称其为' development -base' 在' development -base'之上执行'develop'的交互式重基(即使它已经在顶部)。在交互重基期间,你将有机会删除合并提交和反转合并的提交,即从git历史中删除这两个事件

此时你将拥有一个干净的“开发”分支,你可以像往常一样将你的功能分支合并到其中。

当我遇到同样的问题时,我发现了这篇文章。我发现上面的方式是可怕的做重设顽固性等。我最终会删除一些我不想删除的东西,并且无法恢复。

相反,我签出了我想让分支返回的提交,例如git checkout 123466t7632723。然后转换为一个分支git签出my-new-branch。然后我删除了我不再需要的分支。当然,这只有在你能够扔掉你搞砸的分支的情况下才会起作用。

我建议您按照以下步骤恢复一个恢复,比如SHA1。

git checkout develop #go to develop branch
git pull             #get the latest from remote/develop branch
git branch users/yourname/revertOfSHA1 #having HEAD referring to develop
git checkout users/yourname/revertOfSHA1 #checkout the newly created branch
git log --oneline --graph --decorate #find the SHA of the revert in the history, say SHA1
git revert SHA1
git push --set-upstream origin users/yourname/revertOfSHA1 #push the changes to remote

现在为分支用户/yourname/revertOfSHA1创建PR

要在不破坏工作流程的情况下还原还原:

创建一个develop的本地垃圾副本 在develop的本地副本上恢复恢复提交 将该副本合并到您的特性分支中,并将您的特性分支推到您的git服务器。

当你准备好了,你的特征分支现在应该可以正常合并了。唯一的缺点是在历史记录中会有一些额外的合并/恢复提交。

让我们假设你有这样的历史

---o---o---o---M---W---x-------x-------*
              /                      
      ---A---B

哪里A, B失败的提交和W -是恢复M

所以在我开始修复发现的问题之前,我选择W提交到我的分支

git cherry-pick -x W

然后在我的分支上恢复W提交

git revert W 

之后我可以继续修理。

最终的历史记录如下:

---o---o---o---M---W---x-------x-------*
              /                       /     
      ---A---B---W---W`----------C---D

当我发送一个PR时,它会清楚地显示PR是撤销恢复,并添加一些新的提交。