如何撤消GIT合并南瓜?
我刚刚完成了
git merge --squash feature-branch
开发
分支。
问题在于,上面的命令在没有创建新提交的情况下更新了头部。我的目的是创建一个单一提交,以应用于开发
的头部。
因此,简而言之,合并之前和之后的开发
分支的日志完全相同。
有没有一种方法可以将恢复到
?git Merge
之前开发
谢谢。
解决方案
基于Dan D.的评论以及下面接受的答案,我能够解决我的问题。请参阅下面我所做的事情,以防您在同一条船上:
1-我运行git reflog
,并列出了我对我develop
分支所做的所有提交和结帐。
2-我没有按建议进行git重置头@{1}
,而是找到了我想保留的最后一个提交时的数字。就我而言,它是head@{188}
。因此,我键入git重置头@{188}
。
3-我运行了git日志
,它的日志清洁,仅显示我进行错误合并之前的提交。
4-我运行git add -a。
登台我在功能开发过程中创建的所有新文件。
5-我运行git commit -m“ install feature -x”
6-结果,我现在有了branch 使用正确的文件开发
,日志已清洁 - 仅显示一个提交我在开发feature-x
过程中所做的所有更改。
我仍然需要找出为什么我的原始git合并-squash feature-branch
无法按预期工作。
解决方案2
Mark Longair的答案是解决我问题的确定解决方案。我刚刚测试了它,它有效。请参阅下面的过程,我现在正在使用feature-branch
中的所有内部提交,并仅包含一个提交开发
分支:
git checkout develop
git merge --squash feature-branch
git commit -m "install of feature-branch"
上面的序列就像魅力一样工作。
I have just done a
git merge --squash feature-branch
into my develop
branch.
The problem is that the above command updated the head without creating a new commit. My intention was to create one single commit to apply to the head of develop
.
So in short, the log for the develop
branch before and after the merge are exactly the same.
Is there a way to revert back develop
to what it was before the git merge
?
Thank you.
Solution
Based on the comment from Dan D. and the accepted answer below I was able to resolve my problem. See below what I did in case you are in the same boat:
1 - I ran git reflog
and it listed all the commits and checkouts I did with my develop
branch.
2 - Instead of doing a git reset HEAD@{1}
as suggested, I found the number when I did the last commit to develop that I wanted to keep. In my case it was HEAD@{188}
. So I typed git reset HEAD@{188}
.
3 - I ran a git log
and it had a clean log showing only the commits I had before I did the wrong merge.
4 - I ran git add -A .
to stage all the new files created during my feature development.
5 - I ran git commit -m "install feature-x"
6 - As a result now I have branch develop
with the correct files and the log is clean - showing only one commit for all the changes I did during the development of feature-x
.
I still need to find out why my original git merge --squash feature-branch
did not work as intended.
Solution 2
Mark Longair's answer is a definitive solution to my problem. I have just tested it and it works. See below the process I am using now to squash all the internal commits within a feature-branch
and include just one commit to the develop
branch:
git checkout develop
git merge --squash feature-branch
git commit -m "install of feature-branch"
The above sequence works like a charm.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您运行 git merge --squash工作树和索引将根据合并结果进行更新,但不会创建提交。您需要做的就是运行:
但是,如果您在提交之前改变主意并且只想中止合并,则只需运行:
您不需要使用引用日志。
If you run
git merge --squash <other-branch>
the working tree and index are updated with what the result of the merge would be, but it doesn't create the commit. All you need to do is to run:However, if you change your mind before committing and just want to abort the merge, you can simply run:
You don't need to use the reflog.
如果您在提交之前改变主意,您有以下选择:
使用现代 git 语法中止合并:
使用旧语法:
非常老式:
但实际上,值得注意的是
git merge --abort 仅在存在
MERGE_HEAD
的情况下相当于git reset --merge
。这可以在 git 合并命令帮助中阅读。合并失败后,当没有
MERGE_HEAD
时,可以使用git reset --merge
撤消失败的合并,但不一定使用git merge --abort< /code>,所以它们不仅仅是同一事物的新旧语法。就我个人而言,我发现 git reset --merge 在日常工作中更有用。
If you change your mind before committing, you have these options:
Abort the merge with modern git syntax:
And with older syntax:
And really old-school:
But actually, it is worth noticing that
git merge --abort
is only equivalent togit reset --merge
given thatMERGE_HEAD
is present. This can be read in the git help for merge command.After a failed merge, when there is no
MERGE_HEAD
, the failed merge can be undone withgit reset --merge
but not necessarily withgit merge --abort
, so they are not only old and new syntax for the same thing. Personally I findgit reset --merge
much more useful in everyday work.