如何重新设置合并但保留合并提交 [英] How to rebase a merge but keep the merge commit

查看:55
本文介绍了如何重新设置合并但保留合并提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和我的团队正在使用远离主轨道 (origin/dev) 的远程分支 (origin/our_feature_branch) 开发功能.Gerrit 用于审查等.

Me and my team are developing a feature using a remote branch (origin/our_feature_branch) off of main track (origin/dev). Gerrit is used for review etc.

使用 git merge origin/dev 提升远程分支,然后修复冲突,提交和 git push origin HEAD:refs/for/our_feature_branch.

Uplifting the remote branch is done with git merge origin/dev followed by fixing conflicts, committing and git push origin HEAD:refs/for/our_feature_branch.

Gerrit 强制执行一项规则,规定一次只能推送一个提交.我对此无能为力.

Gerrit enforces a rule saying that only one commit at a time can be pushed. I cannot do anything about this.

假设我开始努力提升:

git fetch
git checkout -b uplift origin/our_feature_branch
git merge origin/dev

但是在这里我遇到了解决一些冲突的问题,并且回归测试需要一些时间才能运行,并且一些团队成员向 Gerrit 中的功能分支提交了另一个提交.此提交现在位于我正在进行的"提升的基础提交之上.

But here I get stuck fixing some conflicts and the regression tests take some time to run, and some team member submits another commit to the feature branch in Gerrit. This commit is now on top of the base commit for my "ongoing" uplift.

我现在该怎么办?

如果我在功能分支上重新设置我的合并提交,我会删除合并并将所有从 origin/dev 合并的提交添加到它上面 - 这不是一个选项.如果我与功能分支合并,我最终会在合并时进行合并,并且我最终不得不向 Gerrit 推送两次提交 - 也是不允许的.

If I rebase my merge commit on the feature branch I remove the merge and add all commits merged in from origin/dev on top of it - not an option. If I merge with the feature branch I will end up with a merge on a merge and I will end up having to push two commits to Gerrit - also not allowed.

是否有解决方案,或者我是否必须重新进行合并,并尝试记住在下次我开始进行提升时告诉所有人我们将停止交付?

Is there a solution to this or do I have to re-do the merge and try to remember to tell everyone that we have a delivery stop next time I start working on an uplift?

推荐答案

正如评论中所建议的,git rebase -p 解决了这个问题

As suggested in comments, git rebase -p solves the issue

开始创建提升提交:

git fetch
git checkout -b uplift origin/our_feature_branch
git merge origin/dev
git commit

某些内容已提交到 Gerrit 中的 origin/our_feature_branch.

Something is submitted to origin/our_feature_branch in Gerrit.

执行以下操作以重新设置合并提交并保留合并:

Do the following to rebase the merge commit and keep the merge:

git fetch
git rebase -p origin/our_feature_branch

现在可以将合并提交推送到 Gerrit,它将基于 origin/our_feature_branch 上的最新版本以及与 git 之前相同的 origin/dev变基 -p

Now the merge commit can be pushed to Gerrit and it will be based on latest on origin/our_feature_branch and the same origin/dev as before the git rebase -p

这篇关于如何重新设置合并但保留合并提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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