在GitHub上使用Git维护多个应用版本

时间:2018-01-23 18:57:45

标签: git github git-log git-cherry-pick

作为序言,我想说git-flow将解决其中一些问题。我宁愿坚持使用GitHub PR来处理功能和修补程序分支。我也更喜欢改变功能分支。我遵循这样的口号,即每次提交都应该有一整套通过测试。如果您合并上游提交,则无法保证所有提交都将通过测试,而无需在每次提交时重新运行测试。

我有分支机构PROD和DEV。 PROD应始终位于DEV的上游。如果我有一个需要转到PROD的修复程序,这就是我要做的事情:

  • 从PROD分支并创建修复 - >提交X
  • 将X合并到PROD并使用git tag ...发布新标记(与GitHub PR合并,以便可以审核修复)
  • 从DEV&& git cherry-pick X然后PR到DEV(这里不需要发布新标签)

现在问题出现在最后一步。如果我忘记了最后一步怎么办?我如何检查是否X'(樱桃挑选提交)在DEV上?保持PROD和Dev最新的最佳方法是什么,或者至少看看它们是否与樱桃选择有所区别?

我玩过git log --cherry-pick DEV..PROD,但提交X仍在显示。

This article提供了一些不错的选择,但我正在尝试解决我必须挑选而不是维护另一个分支的情况。

2 个答案:

答案 0 :(得分:2)

我找到了自己问题的答案。显然,这是一个意见问题,因为有许多潜在的解决方案,但这里是我的:

我现在正在使用git tags来冻结我的PROD分支。对于每个新版本,我都使用新的git-tag更新我的代码库的次要版本。如果我发现需要在上游标签上修复的错误,我会直接在PROD上进行更改,然后选择对DEV的所有更改。例如:

$ git checkout PROD # HEAD is at v1.2.0 
$ # commit the changes
$ git tag v1.2.1
$ git checkout DEV
$ git cherry-pick ..HOTFIX

以上是我所做的简单版本,不考虑GitHub。

相反,我使用GitHub做的是使用Jenkinsghprb plugin来PR到HOTFIX分支到PROD,然后从Jenkins运行发布脚本。任何时候我PR PROD,另一个工作运行比较PROD与dev与以下:

$ git log --cherry-pick --no-merges --right-only DEV...PROD

如果出现任何差异,我会发送通知(我使用Slack plugin,但我确定您可以使用其他同样有效的内容)。

那就是它!设置一切实际上非常简单。如果你(读者)看到我正在做的任何瑕疵,请发表评论,不仅如此,我可以修复我的答案,但也要修复我的实际设置!

答案 1 :(得分:0)

I think your best solution here is to take advantage of the commit message. Include some hotfix identifier (like a JIRA ticket number or a version) in the commit message so that you can search and compare it later.

Any other solution is going to be faulty. For example, say that you have a nice clean hotfix that gets merged into your PROD, but when you attempt to cherry-pick it into DEV you get a conflict. You resolve it, but now the diff for your cherry-pick commit is no longer the same as your PROD commit. The commit message is going to be the best way to tie those two commits together.

Bug tracking tools that integrate with your CVS can help as well, by tracking which "versions" a ticket should be targeted at and then tracking one branch for each version. This will let you know if a ticket is missing a branch, or if the branch was never merged, etc.