我应该多久向源代码控制提交一次更改?在每个小特性之后,还是只在大特性之后?
我正在开发一个项目,有一个长期的功能要实现。目前,我在完成每一大块工作后,即每一个子特性实现和bug修复后提交。我甚至在发现bug后为某些特性添加了一组新的测试之后才提交。
然而,我对这种模式感到担忧。在一个富有成效的工作中,我可能会提交10次。鉴于我使用的是Subversion,这些提交会影响整个存储库,所以我想知道做这么多次是否真的是一个好做法?
我应该多久向源代码控制提交一次更改?在每个小特性之后,还是只在大特性之后?
我正在开发一个项目,有一个长期的功能要实现。目前,我在完成每一大块工作后,即每一个子特性实现和bug修复后提交。我甚至在发现bug后为某些特性添加了一组新的测试之后才提交。
然而,我对这种模式感到担忧。在一个富有成效的工作中,我可能会提交10次。鉴于我使用的是Subversion,这些提交会影响整个存储库,所以我想知道做这么多次是否真的是一个好做法?
当前回答
如果您正在进行重大更改,并且担心会影响其他使用代码的人,那么您可以创建一个新的分支,然后在更改完成后合并回主干。
其他回答
我也喜欢在完成一大块工作后做出承诺,通常一天要做好几次。我认为在小提交中比在大提交中更容易看到发生了什么。如果担心提交太多,可以考虑创建一个分支,并在整个特性完成后将其合并回主干。
这里有一篇相关的博客文章:编程的恐惧:尽早检查,经常检查
一方面,您必须平衡安全性和可恢复性之间的妥协,另一方面,整个项目的变更管理的便利性。
我用过的最好的方案对这个问题有两个答案。
我们使用了两个完全独立的存储库:一个是项目范围的存储库,另一个是我们自己的个人存储库(我们当时使用rcs)。
我们会定期检查我们的个人存储库,几乎每次你保存你打开的文件。因此,个人存储库基本上是一个大的、范围很长的撤销缓冲区。
一旦我们有了一段可以编译、测试的代码块,并被接受为可以普遍使用,它就会被检入到项目存储库中。
不幸的是,这个系统依赖于使用不同的VCS技术才能工作。在使用两个相同类型的VCS时,我还没有找到任何令人满意的方法来实现相同的结果。两个颠覆资料库)
但是,通过在subversion存储库中创建“个人”开发分支,我已经获得了可以接受的结果——定期地检入分支,然后在完成时合并到主干中。
我个人会提交每一组已完成/稳定/编译的逻辑代码,并尽量在没有提交我当天所做的事情的情况下下班。
我同意其中几个回答:不要签入无法编译的代码;如果您关心的是代码或其更改的“备份”,则使用个人分支或存储库;当逻辑单元完成时检入。
One other thing that I would add is that depending on your environment, the check-in rate may vary with time. For example, early in a project checking in after each functional piece of a component is complete makes sense for both safety and having a revision history (I am thinking of cases where earlier bits get refactored as later ones are being developed). Later in the project, on the other hand, entirely complete functionality becomes more important, especially during integration development/testing. A half-integration or half-fix does not help anyone.
至于每次bug修复后的签到:除非修复是微不足道的,否则绝对如此!没有什么比发现一个签入包含三个修复程序并且其中一个需要回滚更令人痛苦的了。在这种情况下,开发人员在一个区域修复了三个错误,而将哪个更改用于哪个错误修复是一场噩梦。
我觉得你不用太担心多久来一次。重要的是什么,什么时候,为什么。说你必须每3小时或每24小时完成一次任务是毫无意义的。有事情要承诺时就承诺,没有事情就不要承诺。
以下是我推荐的版本控制最佳实践的摘录:
[...] If you are doing many changes to a project at the same time, split them up into logical parts and commit them in multiple sessions. This makes it much easier to track the history of individual changes, which will save you a lot of time when trying to find and fix bugs later on. For example, if you are implementing feature A, B and C and fixing bug 1, 2 and 3, that should result in a total of at least six commits, one for each feature and one for each bug. If you are working on a big feature or doing extensive refactoring, consider splitting your work up into even smaller parts, and make a commit after each part is completed. Also, when implementing independent changes to multiple logical modules, commit changes to each module separately, even if they are part of a bigger change. Ideally, you should never leave your office with uncommitted changes on your hard drive. If you are working on projects where changes will affect other people, consider using a branch to implement your changes and merge them back into the trunk when you are done. When committing changes to libraries or projects that other projects—and thus, other people—depend on, make sure you don’t break their builds by committing code that won’t compile. However, having code that doesn’t compile is not an excuse to avoid committing. Use branches instead. [...]