在 Git 中重新进行恢复合并
我在这里遇到了一些问题:我在 Git 中有一个特定于问题的分支 28s
,我将其合并到通用 develop
分支中。 事实证明我做得太快了,所以我使用 git-revert 来撤消合并。 然而,现在是时候将 28s
合并到 develop
中了,但是 git-merge 命令看到了原始合并,并高兴地宣布一切都很好,分支已经存在合并了。 现在我该怎么做? 创建一个'Revert'Revert'28s-> 开发“”'提交? 这似乎不是一个好方法,但我目前无法想象其他方法。
树结构如下:
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.
What the tree structure looks like:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
你必须“恢复恢复”。 根据您如何恢复原始状态,它可能不像听起来那么容易。 查看关于此的官方文档主题。
允许:
You have to "revert the revert". Depending on you how did the original revert, it may not be as easy as it sounds. Look at the official document on this topic.
to allow:
假设您有这样的历史记录
,其中 A、B 提交失败,而 W - 是 M 的恢复
,因此在开始修复发现的问题之前,我会择优挑选 W 提交到我的分支
然后我在我的分支上恢复 W 提交
之后我可以继续修复。
最终的历史记录可能如下所示:
当我发送 PR 时,它将清楚地显示 PR 已撤消恢复并添加了一些新的提交。
Let's assume you have such history
Where A, B failed commits and W - is revert of M
So before I start fixing found problems I do cherry-pick of W commit to my branch
Then I revert W commit on my branch
After I can continue fixing.
The final history could look like:
When I send a PR it will clearly shows that PR is undo revert and adds some new commits.
要在不破坏工作流程的情况下恢复恢复,请执行以下操作:
当您准备好时,您的功能分支现在应该能够正常合并。 这里唯一的缺点是您的历史记录中会有一些额外的合并/恢复提交。
To revert the revert without screwing up your workflow too much:
Your feature branch should now be able to be merged as normal when you're ready for it. The only downside here is that you'll a have a few extra merge/revert commits in your history.
要在 GIT 中恢复还原:
To revert a revert in GIT:
您可以在
devel
分支中使用此命令来丢弃(撤消)错误的合并提交(而不是使用git-revert
),而不是使用git-revert
只是恢复它)。这也将相应地调整工作目录的内容。 小心:
也会被 git-reset 删除。 您指定的提交之后的所有提交
git reset
参数将会消失!因为重置会改写历史。
我建议在尝试此操作之前仔细研究 git-reset 手册页。
现在,重置后,您可以重新应用
devel
中的更改,然后执行这将是从
28s
到devel
的真正合并,就像最初的一个(现在是从 git 的历史记录中删除)。
Instead of using
git-revert
you could have used this command in thedevel
branch to throw away (undo) the wrong merge commit (instead of just reverting it).This will also adjust the contents of the working directory accordingly. Be careful:
too will be erased by the
git-reset
. All commits after the one you specify asthe
git reset
argument will be gone!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 doThis will be a real merge from
28s
intodevel
like the initial one (which is nowerased from git's history).
我建议您按照以下步骤来恢复恢复,例如 SHA1。
现在为分支
users/yourname/revertOfSHA1
创建 PRI would suggest you to follow below steps to revert a revert, say SHA1.
Now create PR for the branch
users/yourname/revertOfSHA1
此时您将拥有一个可以合并的干净的“开发”分支像往常一样,您的功能分支。
At this point you'll have a clean 'develop' branch to which you can merge your feature brach as you regularly do.
我在遇到同样的问题时刚刚发现了这篇文章。 我发现上面的方法很难进行重置等操作。我最终会删除一些我不想要的东西,并且无法将其恢复。
相反,我检查了我希望分支返回到例如 git checkout 123466t7632723 的提交。 然后转换为分支
git checkout my-new-branch
。 然后我删除了我不再想要的分支。 当然,只有当你能够扔掉弄乱的树枝时,这才有效。I just found this post when facing the same problem. I find above wayyy to scary to do reset hards etc. I'll end up deleting something I don't want to, and won't be able to get it back.
Instead I checked out the commit I wanted the branch to go back to e.g.
git checkout 123466t7632723
. Then converted to a branchgit checkout my-new-branch
. I then deleted the branch I didn't want any more. Of course this will only work if you are able to throw away the branch you messed up.如果需要,您可以创建一个新分支,并从恢复的拉取请求中cherry-pick提交(用空格分隔提交 SH,这样它将成为一个命令),这样您就可以合并再次不会丢失文件/更改。
If needed you can create a new branch and cherry-pick the commits (separate the commit SH with space so it will be one command) from the reverted pull request, that way you'll be able to merge again with out losing files/changes.