合并到母版后要素分支上的更改 [英] Changes on feature branch after merge to master

查看:82
本文介绍了合并到母版后要素分支上的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种将变更合并到母版中后将其引入功能分支的方法.目的是使功能分支仅保留与其相关的提交.

I'm looking for a way to introduce changes into feature branches once they have been merged to master. The goal is to keep the feature branch keep only containing commits that are related to it.

在将某个特征推入母版后,通常需要对其进行一些额外的修饰.在那段时间内对母版所做的更改与该功能没有冲突,这意味着在特征分支上执行其他工作时,可以将基础更改为实际的母版.

It often happens that a feature needs some additional polishing after it has already been pushed to master. The changes that have been done to master during that time aren't in conflict with the feature, meaning that a rebase to actual master is possible when implementing the additional work on the feature branch.

下图显示了这种情况:

我到目前为止使用的方法:变基以掌握和合并功能回到掌握

Against->现在,功能分支被来自master的零件污染了.

Against -> The feature branch is now poluted with parts from master.

问题: 您在实践中采用什么方法来解决此问题?

Question: What are the approaches you take in practice to solve this issue?

示例代码

为帮助描述以下方法,是从示例创建回购结构的代码.

To help describe the approaches below is the code to create the repo structure from the examples.

# mkdir test
git init 
touch master-change-file
git add master-change-file
git commit -m "initial commit"
echo 1 > master-change-file
git commit -a -m "master commit 1" 
echo 2 > master-change-file
git commit -a -m "master commit 2" 
git checkout -b feature
echo 3 > feature-change-file
git add feature-change-file
git commit -a -m "feature commit 1"
echo 4 > feature-change-file
git commit -a -m "feature commit 2"
echo 5 > feature-change-file
git commit -a -m "feature commit 3"
git checkout master 
git merge --no-ff feature -m "Merge branch 'feature'"
git checkout feature 
echo 6 > feature-change-file
git commit -a -m "feature commit 4"
echo 7 > feature-change-file
git commit -a -m "feature commit 5"
git checkout master 
echo 8 > master-change-file
git commit -a -m "master commit 3"
echo 9 > master-change-file
git commit -a -m "master commit 3"
# gitk --all

推荐答案

我到目前为止使用的方法:变基以掌握和合并功能回到掌握

Approach i used so far: Rebase to master and merge feature back to master

我认为您可能会对重新定基的目的感到有些困惑.如果将合并master后对功能分支进行了新提交,并且还希望将这些新更改也带入master,则重新基准化是一种选择.考虑下图:

I think you might be slightly confused about the purpose of rebasing. If you have made new commits to a feature branch after merging it to master, and you want to bring those new changes into master as well, then rebasing is one option. Consider the following diagram:

master:  A <- B <- C <- D
feature: A <- B <- C <- E <- F

如果要这样做:

git checkout feature
git rebase master

然后您将被留下:

master:  A <- B <- C <- D
feature: A <- B <- C <- D <- E' <- F'

这时,您只需将feature分支master中,就可以合并它.重新设置基准后,将feature合并到master是没有意义的,并且违反了重新基准化的目的,即保持线性.

At this point, you would simply push the feature branch into master, you would not merge it. Merging feature into master after doing a rebase is pointless, and defeats the purpose of rebasing which is to maintain linearity.

最后,这是您问题的答案.基本上,您有两种选择来处理这些具有新更改的功能分支.您可以合并,也可以变基.由您决定是否保留在功能分支中发生的原始提交.

Finally, here is the answer to your question. You basically have two choices to handle these feature branches which have new changes. You can either merge, or you can rebase. It is up to you whether or not you wish to preserve the original commits which took place in the feature branches.

这篇关于合并到母版后要素分支上的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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