当merge.ff = only时,如何壁球合并? [英] How can I squash merge when merge.ff = only?

查看:74
本文介绍了当merge.ff = only时,如何壁球合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我将merge.ff设置为only,如下所示:

To start with, I have my merge.ff setting to only, as in:

git config --global merge.ff only

我之所以这样,是因为我不希望git在不先与我确认的情况下进行非快进合并.这是确保我有机会做除创建无关的合并提交以外的其他事情的很好的保障.当我确实需要进行非快进合并时,我可以告诉git覆盖我的默认设置:

I have it like this because I don't want git to do non-fast-forward merges without checking with me first. This acts as a nice safeguard to make sure I get the opportunity to do something other than create an extraneous merge commit. When I do need to do a non-fast-forward merge, I can tell git to override my default setting:

git merge --no-ff

现在考虑一个具有如下历史记录的git存储库:

Now consider a git repository with a history like this:

假设出于某种原因,我想将work分支合并到master. (当然,在这种简单的情况下,我可以重新设置基准,但假设我还有其他原因要壁球.)通常,您可以使用--squash参数进行壁球合并:

Let's say for some reason I want to squash merge the work branch onto master. (In a case this simple, I could just rebase, of course, but suppose I had some other reason to squash instead.) You normally do a squash merge with the --squash argument:

git checkout master
git merge --squash work

但是在这种情况下,它会导致错误消息:

But in this instance, it results in an error message:

fatal: Not possible to fast-forward, aborting.

这种说法很有道理.无法快速合并 ,因为两个分支的提交都不相同.但这也没关系:无论如何,我都想进行合并.显而易见的解决方案是使用--no-ff,就像我通常会告诉git的那样,它应该可以继续进行,

This kind of makes sense. A fast-forward merge isn't possible because both branches have commits that are not in common. But this is also okay: I want to do a merge anyway. The obvious solution is to use --no-ff like I normally would to tell git that this is okay and it should proceed anyway:

git merge --squash --no-ff work

但这也会产生错误:

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

那么如何在不更改配置的情况下让git进行壁球合并?

So how do I get git to squash merge without changing my configuration?

推荐答案

答案

使用git -c merge.ff merge --squash <args>.

壁球合并"根本不是真正的合并(实际上也不是快进合并),因此git拒绝使用config设置拒绝它们似乎是一个错误.

Squash "merges" are not really merges at all (and in fact, neither are fast-forward merges), so it seems like a bug that git rejects them with the config setting.

尽管如此,您可以暂时覆盖merge.ff=only设置.实验表明,该方法有效(此外,与stash合并是荒谬的,但我在此存储库中碰巧有一个,而我实际上并没有在这里合并):

That said, though, you could temporarily override your merge.ff=only setting. Experimentation shows that this works (aside, merging with stash is nonsensical but I happen to have one in this repo and I'm not actually merging here):

$ git config --global merge.ff=only
$ git merge --squash stash
fatal: Not possible to fast-forward, aborting.
$ git -c merge.ff=false merge --squash stash
fatal: You cannot combine --squash with --no-ff.
$ git -c merge.ff=true merge --squash stash
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested

(这时我只用git reset --hard撤消伪造的合并).

(at which point I just use git reset --hard to undo the fake merge).

由于-c默认为=true,因此答案在顶部.

Since -c defaults to =true, we get the answer at the top.

这篇关于当merge.ff = only时,如何壁球合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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