问题描述
我刚刚完成了一个
git merge --squash feature-branch
放入我的开发
分支。
问题在于上面的命令更新了头部而未创建新的提交。我的意图是创建一个单独的提交以应用于开发
的头部。
develop
分支完全相同。 有没有办法恢复开发
到 git merge
?
谢谢。
解决方案
Dan D.的评论和下面我接受的答案能够解决我的问题。如果你在同一条船上,请看下面的内容:
- 我运行了
git reflog
列出了我对 develop
分支所做的所有提交和结账。 2 - 不是做一个 git reset HEAD @ {1}
按照建议,当我做了最后一次我希望保留的承诺时,我找到了这个数字。在我的情况下,它是 HEAD @ {188}
。所以我输入了 git reset HEAD @ {188}
。
$ b $ 3我运行了一个
git log
,它有一个干净的日志,只显示我在进行错误合并之前提交的提交信息。 4 - 我运行了 git add -A。
来展示我在功能开发期间创建的所有新文件。
- 我运行了
git commit -minstall feature-x
6 - 现在我有分支 develop
与正确的文件和日志是干净的 - 在开发 feature-x
时所做的所有更改只显示一个提交。
我仍然需要找出为什么我原来的 git merge --squash feature-branch
不能按预期工作。 / p>
解决方案2
Mark Longair的答案是我的问题的确切解决方案。我刚刚测试过它,它工作。请参阅下面我现在用来压缩特性分支
中的所有内部提交的流程,并仅包含一个提交给 develop
$ b
git checkout开发
git merge --squash特性分支
git commit -m安装功能分支
上述顺序就像一个魅力一样。
如果您运行 git merge --squash< other-branch>
树和索引用合并的结果进行更新,但不创建提交。所有你需要做的就是运行:
git commit
然而,如果您在提交之前改变了主意,只想放弃合并,您可以直接运行:
git reset --merge
您不需要使用reflog。
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.
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:
git commit
However, if you change your mind before committing and just want to abort the merge, you can simply run:
git reset --merge
You don't need to use the reflog.
这篇关于如何撤消git merge squash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!