简体   繁体   English

合并为master后功能分支的更改

[英]Changes on feature branch after merge to master

I'm looking for a way to introduce changes into feature branches once they have been merged to master. 我正在寻找一种方法,一旦将功能分支合并到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. 在此期间对master进行的更改与该功能不冲突,这意味着在功能分支上实现其他工作时,可以对实际master进行更改。

The image below shows the situation: 下图显示了这种情况:

在此输入图像描述

Approach i used so far: Rebase to master and merge feature back to master 到目前为止我使用的方法:Rebase to master并将功能合并回master

在此输入图像描述

Against -> The feature branch is now poluted with parts from master. 反对 - >功能分支现在与来自master的部件混合。

在此输入图像描述

Question: What are the approaches you take in practice to solve this issue? 问题:您在实践中采取了哪些方法来解决此问题?

Example code 示例代码

To help describe the approaches below is the code to create the repo structure from the examples. 为了帮助描述以下方法,可以从示例中创建repo结构的代码。

# 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 到目前为止我使用的方法:Rebase to 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. 如果在合并master之后对功能分支进行了新的提交,并且您希望将这些新更改也添加到master中,那么rebasing是一个选项。 Consider the following diagram: 请考虑以下图表:

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

If you were to do: 如果你这样做:

git checkout feature
git rebase master

then you would be left with: 然后你会留下:

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

At this point, you would simply push the feature branch into master , you would not merge it. 在这一点上,你只需 feature分支成master ,你就不会合并。 Merging feature into master after doing a rebase is pointless, and defeats the purpose of rebasing which is to maintain linearity. 在执行rebase之后将feature合并到master是没有意义的,并且违背了用于保持线性的rebasing的目的。

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. 无论您是否希望保留在功能分支中发生的原始提交,都取决于您。

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

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