简体   繁体   English

从源分支移动提交,但在目标分支将合并回原位时保留提交?

[英]Moving commits from source branch, but keeping them when target branch will be merged back in?

We starting developing a feature in the dev branch but realized it was going to take much longer, so we created a feature branch in the middle of development for the remaining changes. 我们开始在dev分支中开发功能,但是意识到这将花费更长的时间,因此我们在开发过程中为其余更改创建了功能分支。

The commits are not contiguous in the dev branch. 提交在dev分支中不连续。 We would like to revert those commits on the dev branch for preparation of a release without any of the feature branch code. 我们希望在dev分支上还原这些提交,以准备发布而无需任何功能分支代码。

We have this: 我们有这个:

A--Fa--B--Fb--C--D--E--F--G   <-- dev
               \
                Fc--Fd--Fe    <-- feature

We want this: 我们想要这个:

A--B--C--D--E--F--G   <-- dev
 \
  Fa--Fb--Fc--Fd--Fe  <-- feature

And this is easily possible via reverting the Fa , Fb commits on the dev branch. 通过恢复FaFb在dev分支上的提交,这很容易实现。 But, when the time comes to merge the feature branch in, will git complain? 但是,当需要合并功能分支时,git会抱怨吗?

A--B--C--D--E--F--G--H--   <-- dev
 \                  /
  Fa--Fb--Fc--Fd--Fe        <-- feature

The answer appears to be yes ... and I wonder if there's a way to avoid that? 答案似乎是肯定的 ,我想知道是否有办法避免这种情况?

This question is almost exactly what I am asking -- but my commits are not contiguous. 这个问题几乎完全是我要问的-但是我的提交不是连续的。 Does that matter? 有关系吗

I cannot (easily) rewrite the history--but I suppose it's possible (only 2 other devs have the repository). 我无法(轻松地)重写历史记录,但是我想这是可能的(只有其他两个开发人员拥有该存储库)。

So after playing with git a bit, the only option was to revert the commits, reset the dev branch, and recommit everything since (including non-feature work) as one giant blob, force push and then merging would sort-of work better down the line. 因此,在稍微使用git之后,唯一的选择是还原提交,重置dev分支,然后重新提交所有内容,因为(包括非功能性工作)是一个巨大的blob,强制推送然后合并将更好地完成工作线。

It was just easier to comment out a few lines to make the code dead. 注释掉几行以使代码无效只是更容易。

In my opinion you can hard reset your dev branch to commit A. Then you can start a new feature branch there, then cherry pick the appropriate commits for both the branches. 在我看来,您可以将自己的dev分支硬重置为提交A。然后您可以在此处启动一个新的功能分支,然后为这两个分支挑选合适的提交。 When you are done cherry picking the commits, delete the old feature branch. 完成选择提交的工作后,请删除旧功能分支。 I think you will elegantly achieve the state that you want. 我认为您将优雅地实现所需的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM