Git 功能分支和小代码改进
我们刚刚开始使用 git 来编写生产代码,并且在工作流程中遇到了一个小问题。我们需要弄清楚如何处理在开发某个功能时出现的一般代码改进/技术债务修复。
我们采用的工作流程是使用develop作为主要集成分支,并开发develop的feature分支上的所有功能。当一项功能完成后,开发人员会创建一个拉取请求,每个人都会对其进行审查以提供评论,然后再将其合并回开发中。这看起来效果很好。
我们遇到的问题是,在功能的日常开发过程中,开发人员可能最终想要修改/重构一些通用代码以改进系统或清理一些技术债务。此更改很有价值,但与正在开发的功能没有直接关系。
根据我们的工作流程,它实际上应该在不同的分支上完成,该分支在进入开发之前要经过自己的拉取请求和代码审查。
如果我们让他们这样做,那么在等待完整的代码审查以及代码合并到开发中的同时,他们如何才能将更改返回到他们的功能分支上。
我们的想法是:
将 refactorX 分支中的更改精挑细选到我们的功能分支中。继续开发并让 git (希望)弄清楚当我们合并回开发时它已经具有来自重构分支的更改。
将refactorX分支合并到我们的功能分支中并继续开发。 (注意:refactorX的分支develop可能在develop历史上较晚,所以我们认为这可能有问题)
我们尚不知道其他一些更智能的选项。 :)
我们正在寻找一些关于如何处理这部分工作流程的最佳实践指南。经过更多讨论后,我们知道它会经常出现,我们希望找到一种平稳有效的方法来在我们的工作流程中处理它。
有什么建议吗?
We just started using git for our production code, and we are running into a slight issue in our workflow. We need to figure out how to handle general code improvements / technical debt fixes that come up while working on a feature.
The workflow we have adopted is to use develop as the main integration branch and develop all features on feature branches off of develop. When a feature is complete, the developer creates a pull request and everyone reviews it to provide comments before it is merged back into develop. This seems to be working very well.
The issue we have is that during routine development on a feature, the developer may end up wanting to modify/refactor some common code to improve the system or clean up some technical debt. This change is valuable, but not directly tied to the feature under development.
Based on our workflow, it should really be done on a different branch that goes through its own pull request and code review before getting into develop.
If we have them do this though, how can they get the change back over onto their feature branch in the meantime while they wait for the full code review to happen and the code to get merged into develop.
The ideas we have are:
cherry-pick the changes from the refactorX branch into our feature branch. Continue developing and let git (hopefully) figure out when we merge back to develop that it already has the change from the refactor branch.
Merge the refactorX branch into our feature branch and continue development. (note: the branch off develop for refactorX may have been later in the history of develop, so we think this may have problems)
Some other smarter option we don't know yet. :)
What we are looking for is some best practice guidance on how to handle this part of the workflow. After talking about it more we know that it will come up frequently and we want to find a smooth and efficient way to handle it in our workflow.
Any recommendations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第三种选择是开发人员将所有功能分支重新建立到已重构的分支上(因此重构更改会合并到他们的所有工作中)。然后,您确保首先审查重构分支并将其合并回开发分支。然后,所有功能分支都将基于开发,您可以像平常一样将它们合并(即合并一个,将其他分支重新基于开发,重复)。
在 ASCII 艺术中,在回顾重构之前:
然后:
然后,如果您完成了 feature1 并将其合并到:
您再次将 feature2 重新建立到开发中:
然后您可以像往常一样合并 feature2:
A third option is for the developer to rebase all of their feature branches onto the branch which has been refactored (so the refactoring changes are incorporated in all of their work). You then make sure that the refactoring branch is reviewed first and merge that back into the development branch. All of the feature branches will then be based off development and you can merge them in as you would normally (i.e. merge one, rebase the others onto development, repeat).
In ASCII art, prior to reviewing refactoring:
And afterwards:
Then, if you finish feature1 and merge it in:
You rebase feature2 onto development again:
And then you can merge feature2 in as usual:
看来您正在尝试避免将开发分支合并回功能分支。避免此步骤是有益的,但有时这是必要的,尤其是在这种情况下。
我们开始使用的一项技术是 git rebase --onto 。可以将功能分支移动到开发分支的末尾以获取新功能,而不是将开发分支合并到功能分支中。
当您使用中央存储库时,创建新的功能分支名称可能最有用。例如,我们将 -v2 附加到新分支名称上。
典型的移动过程可能看起来像
现在您的功能分支中有新代码,但尚未将开发分支合并到功能分支中。
It appears that you are trying to avoid merging the develop branch back into the feature branch. It is beneficial to avoid this step, but sometimes it is necessary, especially in situations such as this.
A technique that we are starting to use also is
git rebase --onto
. Instead of merging the develop branch into the feature branch, the feature branch can be moved to the end of the develop branch in order to acquire the new features.When you are using a central repository, it's probably most useful to create a new feature branch name. For example we append -v2 onto the new branch name.
The typical move process might look like
Now you have new code in your feature branch but haven't merged the develop branch into the feature branch.