Keeping feature branch up to date

时间:2016-04-04 18:51:19

标签: git git-flow

Recently we started using Gitflow for our projects and we are experiencing some problems we cannot wrap our head around.

We have the default setup with the master, develop, feature/xyz and hotfix branches. So assume I am working on a long term feature, let's call this feature/long-time. My colleagues are in the mean time working on feature/short-time. Imagine that after some work, they will commit feature/short-time in to develop and I occasionally commit feature/long-term so they can see my progress and it is safely backed up.

Naturally, the feature/long-term cannot ignore the develop branch for too long or it will fall behind. So how can we periodically sync the changes to the develop branch to the feature/long-term branch?

I have come across two options:

  • Simply doing git merge every now and then. However, I feel like this is not really correct according to Gitflow's philosophy
  • I have seen git rebase a few times now too, however this seems to work only if you do not push your changes to the remote branch, is that correct?

To wrap up: how do I correctly keep my feature branche(s) up to date?

1 个答案:

答案 0 :(得分:2)

这再次带回了合并与rebase的讨论,该讨论已经多次解决。长话讲述,您可以查看here 正如你所说的那样,如果你正在推动你的分支,那么改变是不好的,因为改变你的git历史会让你强迫推动,这对于每天都不好,但一般来说,变基是#34 ;清洁"而不是合并,所以:

  • 如果您必须出于任何原因经常推送您的分支(代码审查,分支的CI构建等),您最好的选择是merge
  • 如果您能够以独立的方式完全工作,避免经常推送您的更改,那么rebase可能是更好的选择。

如果您在一项非常长的任务中工作,即使rebase是您的主要策略,不时合并也是一个好主意,因为:    1.您的更改会不时在远程存储库中备份    2.重新定义大量提交是不切实际的,因为diff是通过commit提交计算的,而在合并中,它是同时为所有提交计算的。这意味着对于大量提交,您可能需要解决不必要的大量冲突,这些冲突可以通过合并减少到每个文件一个。

总而言之,我建议大部分时间都要进行反驳,以保持一个干净的存储库,但不时合并,以便在回购中备份你的分支并照亮未来的rebase。