如何实现`git --no-ff --ff-only`这是不允许的 [英] How to achieve `git --no-ff --ff-only` which is not allowed
问题描述
git merge --ff-only
此外,我想记录主题分支与一个空的提交的集成,这就是为什么我想使用--no-ff来强制这种行为:
git merge --no-ff
然而,我真正想要的是两者的组合:只有当它是微不足道的合并,但让我记录它。 Git认为
致命:您不能将--no-ff与--ff-only结合使用。
这对某些人来说是不言而喻的。
git merge --edit --no -ff topicbranch
不能实现我想要的行为。那么我怎么能合并--no-ff选项,如果有问题的主题分支被重定向到最新的主提交?
更新:看起来像查尔斯贝利的答案会做的伎俩。如果你希望把这个变成一个git别名,你可以在这里发布:
git config --global alias.integrate' !test$(git merge-base HEAD$ 1)=$(git rev-parse HEAD)&& git merge --no-ff --edit $ 1 ||
- 编辑
注意提交消息编辑的强制。
您不需要 - ff-only
因为您你想做一个合并提交, - ff-only
会禁止。
你想要的检查可以在运行合并命令之前作为单独的检查。你可以把它打包成一个简单的shell函数。
例如
merge_if_ahead(){
if test$(git merge-base HEAD$ 1)=$(git rev-parse HEAD);然后
git merge --no-ff$ 1
else
echo>& 2不更新;拒绝合并
return 1
fi
}
As part our rebase-heavy workflow, I am hoping to use a merge on the master branch. In particular I want to merge only when the topic branch has been rebased onto the most recent master commit thereby making any merge a fast-forward one. I can achieve that by using:
git merge --ff-only
Furthermore, I would like to record the integration of the topic branch with an empty commit which is why I would like to use --no-ff which forces that behaviour:
git merge --no-ff
What I really want, though, is a combination of both: merge only when it's trivial but let me record it anyway. Git thinks that
fatal: You cannot combine --no-ff with --ff-only.
which appears self-evident to some.
git merge --edit --no-ff topicbranch
doesn't achieve the behaviour I want either. So how can I merge with the --no-ff option iff the topic branch in question is rebased to the latest master commit?
UPDATE: Seems like Charles Bailey's answer will do the trick. If you desire to have this rolled into a git alias you could issue this here:
git config --global alias.integrate '!test "$(git merge-base HEAD "$1")" = "$(git rev-parse HEAD)" && git merge --no-ff --edit $1 || echo >&2 "Not up-to-date; refusing to merge, rebase first!"'
A bit of a mouthful but works. Note the force of a commit message edit with option --edit
.
You don't want --ff-only
because you do want to make a merge commit which --ff-only
would inhibit.
The check that you want can be made as a separate check before running the merge command. You could package this into a simple shell function.
E.g.
merge_if_ahead () {
if test "$(git merge-base HEAD "$1")" = "$(git rev-parse HEAD)"; then
git merge --no-ff "$1"
else
echo >&2 "Not up to date; refusing to merge"
return 1
fi
}
这篇关于如何实现`git --no-ff --ff-only`这是不允许的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!