Git:如何在不引起合并提交的情况下合并上游更改?

时间:2013-11-26 16:35:50

标签: git git-merge git-rebase git-cherry-pick

我有(提交是按字母顺序创建的)

origin/topic  A-B-C-D-W-X

topic         A-B-C-D-Y-Z

有没有办法让我的topic分支看起来像

A-B-C-D-W-X-Y-Z

没有引入合并提交?


通常我只是做

$ git checkout topic
$ git fetch origin
$ git merge --ff-only origin/topic

但由于YZWX之后提交,快进将无效。

我怀疑一些聪明的变调或樱桃采摘可能会奏效,但我无法包装我的 绕过它:{

4 个答案:

答案 0 :(得分:10)

您可以尝试:

git checkout topic
git pull --rebase origin topic

查看有关rebase选项的fetch man page注释。

我建议使用像git-smart这样的东西,它会在可能的情况下快速前进(更快),如果没有,那么就是一个rebase。如果您有任何更改,它还会隐藏本地更改,并为您提供已拉动的远程更改的摘要。

答案 1 :(得分:5)

作为mamapitufo's answer的替代方案,您还可以执行以下操作,这将为您提供完全相同的结果:

git fetch origin
git rebase origin/topic topic

如果您已将其签出,则最后一个topic参数是可选的。

答案 2 :(得分:2)

如果您已经检出topic并且origin/topic获取了跟踪来源/主题(听起来像你这样做),您可以:

git rebase

我给了mamapitufo投票。

答案 3 :(得分:0)

这可能是也可能不是一个好的答案。来自man git-merge:

   --commit, --no-commit
       Perform the merge and commit the result. This option can be used to
       override --no-commit.

       With --no-commit perform the merge but pretend the merge failed and
       do not autocommit, to give the user a chance to inspect and further
       tweak the merge result before committing.
相关问题