Git 纪律:组合多个功能分支,但仍将它们分开?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5082161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Discipline: combining multiple feature branches, but still keeping them separate?
提问by KarateSnowMachine
The current project I'm working on, I am trying to explore a bunch of different ideas which usually manifest themselves as a bunch of feature branches. The features I'm working on are generally orthogonal to one another, so there are times when I want to merge all of these features (or some subset of the features) and test them out together.
我正在从事的当前项目,我试图探索一堆不同的想法,这些想法通常表现为一堆功能分支。我正在处理的功能通常彼此正交,因此有时我想合并所有这些功能(或某些功能子集)并一起测试它们。
So far my workflow has been this -- I have branches featureA
, featureB
, featureC
and I'll have a branch called featureA_featureB
and then another one like featureA_featureB_featureC
, etc.
到目前为止,我的工作流程一直是这个-我有分支机构featureA
,featureB
,featureC
我会呼吁一个分支featureA_featureB
,然后又一个像featureA_featureB_featureC
等
I am having 2 problems:
我有两个问题:
- The naming scheme is terribly cumbersome and generates a lot of branch clutter
- Since I'm testing the branch with the features that are merged together, I tend to accidentally commit to the combination branch rather than the individual branch. So for example, I think of an improvement to
featureC
, but since I'm in thefeatureA_featureC
branch, I accidentally commit to this branch instead (I really need to stop usinggit commit -a
). Then I have to cherry pick the commit or do some other crazy stuff to get the commit to the right place. - I just feel like there's some better way to accomplish this...
- 命名方案非常麻烦,并且会产生很多分支混乱
- 由于我正在测试具有合并在一起的功能的分支,因此我倾向于不小心提交到组合分支而不是单个分支。例如,我想到了对 的改进
featureC
,但是由于我在featureA_featureC
分支中,我不小心提交到了这个分支(我真的需要停止使用git commit -a
)。然后我必须挑选提交或做一些其他疯狂的事情来将提交提交到正确的位置。 - 我只是觉得有一些更好的方法可以实现这一点......
Thanks in advance!
提前致谢!
采纳答案by Marcin Zalewski
I was going to write an answer of my own, but then I found this great answer(and a great question). It does not give you a single way to do things, but upon a careful reading, you should be able to find a workflow that suits your situation.
我打算自己写一个答案,但后来我找到了这个很好的答案(也是一个很好的问题)。它没有为您提供单一的做事方式,但仔细阅读后,您应该能够找到适合您情况的工作流程。
回答by ralphtheninja
I'd have a common denominator branch for example "develop", where all my feature-branches would branch off from.
我有一个共同的分支,例如“开发”,我所有的功能分支都会从那里分支出来。
develop
|----featureA
|----featureB
|----featureC
Then once you want to test something out, just merge from the feature branches into develop in the combo you want, e.g.
然后一旦你想测试一些东西,只需从功能分支合并到你想要的组合中的开发,例如
git checkout develop
git merge featureA featureB
./test.sh
And keep the commit if you are happy with the test. If not do
如果您对测试感到满意,请保持提交。如果不做
git reset --hard HEAD^
and you are back to develop the way it was before you made the merge. This way you only need your feature branches and you can experiment with them in any combinations. Just remember as long as you have committed anything you can ALWAYS revert to that state by checking the reflog.
你又回到了合并之前的开发方式。这样你只需要你的功能分支,你可以用任何组合来试验它们。请记住,只要您提交了任何内容,您就可以通过检查 reflog 始终恢复到该状态。
And for your git commit -a problems
, do
而对于你的git commit -a problems
,做
git reset --soft HEAD^
and you have the index the way it was just before you made the commit. Then just switch to another branch and commit there instead.
并且您拥有提交之前的索引。然后只需切换到另一个分支并在那里提交。
回答by naXa
In Git, there are several ways to integrate changes from one branch into another: Merge branches, Rebase branches, or Apply separate commits from one branch to another (cherry-pick).
在 Git 中,有几种方法可以将更改从一个分支集成到另一个分支:合并分支、重新设置分支或将单独的提交从一个分支应用到另一个分支(樱桃挑选)。