简体   繁体   English

如何在Git中实现语义版本控制?

[英]How Do I Implement Semantic Versioning in Git?

I've been able to convince my group to use semantic versioning and move to git (from CVS, where all development happened on the trunk). 我已经能够说服我的小组使用语义版本控制并转移到git(来自CVS,所有开发都发生在主干上)。

This is what we've been using for a bit (where the version branches denote the introduction of some kind of new functionality): 这就是我们一直在使用的东西(版本分支表示某种新功能的引入):

master
*
|
*   * version 2.0 branch
|  /
* *
|/
*   * version 1.0 branch
|  /
* *
|/
*
|
...

The problem is that when there's a bugfix that needs to be made on the version 1.0 branch, that fix needs to get echoed up to version 2.0 and master. 问题是,当需要在版本1.0分支上进行错误修复时,该修补程序需要回显到版本2.0和主数据库。 We've been cherry-picking, but I feel like that's more error-prone than I'd like (and I feel like it'll become unmanageable as time goes on). 我们一直在挑选,但我觉得这比我想要的更容易出错(我觉得随着时间的推移它会变得无法管理)。

There are some limitations to what we're doing--it's legacy code, and there isn't a lot of testing being done (starting to introduce unit testing, very little integration testing), so keeping stability on those version branches (not introducing a lot of regression errors) is important. 我们正在做的事情有一些限制 - 它是遗留代码,并且没有进行大量测试(开始引入单元测试,非常少的集成测试),因此保持这些版本分支的稳定性(不介绍很多回归错误)很重要。

Do you guys have a better way to approach this than cherry-picking? 你们有没有比采摘樱桃更好的方法来解决这个问题? Is there a better workflow to use? 有更好的工作流程可供使用吗? Really appreciative of any help you can provide. 非常感谢您提供的任何帮助。

Cherry-picking can: 樱桃采摘可以:

I prefer merging (which is similar to A successfull Git branching mentioned by desert69 ): 我更喜欢合并 (类似于desert69 提到成功的Git分支 ):

  • create a branch dedicated to that buxfix_xxx (on top of version1) 创建一个专用于buxfix_xxx的分支(在版本1之上)
  • merge version1 to that buxfix_xxx branch (fast-forward) 将version1合并到该buxfix_xxx分支(快进)
  • merge buxfix_xxx to version 2 and master branches buxfix_xxx合并到version 2master分支

Of course, the trick is to record a merge in those branches (version2 and master) without actually merging all the files: see " How do you merge selective files with git-merge? ". 当然,诀窍是在这些分支(版本2和主版)中记录合并而不实际合并所有文件:请参阅“ 如何使用git-merge合并选择性文件? ”。

If you have only a few files to merge, here is what I do: 如果你只有几个文件要合并,我就是这样做的:

# make git believe we are merging everything
git checkout version2
git merge --no-commit bugfix_xxx

# but reset everything to version2
# (while the merge is still in progress!)
git checkout version2 -- .

# merge only the few files we need:
git checkout --patch bugfix_xxx -- path/to/file1
git checkout --patch bugfix_xxx -- path/to/file2
git checkout --patch bugfix_xxx -- path/to/file3

# add and commit, concluding the merge

The nice thing about those merges is that, the next one (from version1 to version2 and master ) will naturally be limited to the next bugfix, because git will believe that everything else was already merge ! 关于那些合并的好处是,下一个(从version1version2master )将自然限于下一个错误修复,因为git将相信其他一切 已经合并

So the time you invest in that first backport of a bugfix will pay of for the next ones. 因此,您投入第一个错误修正后端的时间将为下一个支付费用。

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

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