Git 撤消合并 3 个分支
我对 Git 不是很熟悉。我已经掌握了基础知识,但仅此而已。
不管怎样,我的朋友引导我完成了这三个分支的合并。不过他让我自己运行 mergetools 部分。我没有正确进行合并,但已经推送了更改。有什么方法可以撤消我的更改,使其恢复为 3 个不同的分支,然后再次合并?
编辑*
不是 100% 确定它是否重要,但其中 2 个分支来自上游。
I am not very familiar with Git. I have the basics down, but thats about it.
Anyway, my friend walked me through merging these 3 branches. He left me to run the mergetools part myself though. I didn't do the merge correctly, but had already pushed the changes. Is there some way I can undo my changes so it goes back to being 3 different branches, and then merge again?
edit*
Not 100% sure if it matters, but 2 of the branches are from upstream.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例如使用 git log 找出最后一个干净状态的提交 ID(即合并之前的提交)并重置为该 ID。
之后,强制推送你的旧状态。
注意:
reset --hard
将丢弃未暂存的更改,因此请确保有一个干净的工作目录。如果不确定,请执行git stash
。此外,如果您没有对合并状态进行任何进一步的工作,即从那时起您没有提交任何内容,那么这只会毫无问题地工作。
手册页:
Find out the commit ID of the last clean state (i.e. the commit before the merge) for example with
git log
and reset to that.After that, force push your old state.
Be aware:
reset --hard
will discard unstaged changes, so be sure to have a clean working directory. Do agit stash
if not sure.Additionally, this will only work without problems, if you didn't do any further work on the merged state, i.e. you didn't commit anything since then.
Man pages:
您可以使用 git revert <>,但是在上次干净提交和当前
head
之间会有很多提交。我不太了解 git 命令,但必须有一种方法可以打印其间的所有提交。您可以编写一些脚本来仅提取 SHA 并将其全部恢复。不过我对此并不是 100% 确定。 :)
You may use
git revert <>
, but there would be so many commits between the last clean commit and the currenthead
. I don't know much of the git commands, but there must be a way to print all the commits in between. You may write some script to extract only the SHAs and revert them all.I am not 100% sure about this though. :)