git与--no-ff和--squash合并 [英] git merge with --no-ff and --squash

查看:358
本文介绍了git与--no-ff和--squash合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用git flow方法来管理我的仓库中的分支,如以下所述: http://nvie.com/posts/a-successful-git-branching -model/

I am using the git flow way of managing branches in my repo, as described in: http://nvie.com/posts/a-successful-git-branching-model/

因此,我应该使用的命令顺序如下:

Thus the sequence of commands I should use would be as follows:

git checkout mybranch
git pull --rebase origin develop
git checkout develop
git merge --no-ff mybranch

但是,在某些情况下,我想做另一件事:

However, there is one thing that I would like to do differently, in some cases:

我想将所有提交保留在功能分支(mybranch)上,但是在合并到develop时将它们集中在一起(或压缩)为单个差异.

I would like to preserve all of my commits on my feature branch (mybranch), but have them lumped together (or squashed) into a single diff when merging into develop.

这就是我认为的命令顺序:

So this is what I think the sequence of commands should be:

git checkout mybranch
git pull --rebase origin develop
git checkout develop
git merge --no-ff --squash mybranch

如果将--no-ff--squash结合使用,我会做错什么吗?

Would I be doing things wrong if I were to combine --no-ff with --squash?

我很犹豫地尝试此操作,原因是挤压"和保存历史"是正交的要求-请参阅

I am hesitant to try this out stems from how "squashing" and "preserving history" are orthogonal requirements - see Squashing all of my commits (including merges) into one commit without altering history

我的理由是我想保留一个分支(mybranch)上的历史记录,而另一个分支(develop)上的suqash->因为这些操作是在单独的分支中执行的,所以可以.

My rationale is that I want to preserve history on one branch (mybranch) and suqash on another branch (develop) --> because these actions are performed in separate branches, this is OK.

推荐答案

我尝试将--squash和--no-ff组合在一起并得到:

I tried combining --squash and --no-ff together and got:

fatal: You cannot combine --squash with --no-ff.

一个git merge基本上是南瓜.解决冲突后,它将显示为一次开发.合并修订的差异是冲突解决的结果.是的,保留了mybranch上的更改.只需执行"gitk mybranch&"合并后进行验证.

A git merge basically is a squash. After resolving conflicts, it will appear as one commit on develop. The diff of the merge revision is the result of conflict resolution. And yes the changes on mybranch are preserved. Just do "gitk mybranch &" after the merge to verify.

在阴影旁边是正确的.不要害怕.创建一个新分支,玩转看看结果如何.

Besides The Shadow is correct. Do not be afraid. Create a new branch, play around and see what the results are.

损坏是通过您的"git pull --rebase原点开发"命令造成的.

The damage was done in your "git pull --rebase origin develop" command.

答案(假设您有基于起源/发展的本地发展分支):

Answer (assumes you have local develop branch based on origin/develop):

git checkout develop
git pull
git merge --no-ff mybranch

这篇关于git与--no-ff和--squash合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆