使用 dvcs/git,单个提交是否优于多个小型主题提交?
这可能不是 git 特定的问题,但它是在 git 的上下文中出现的。这个想法可能更广泛地适用于其他风险投资。
我正在开发一个小项目,目前我是唯一的开发人员。我已经习惯使用 git,所以我想知道最佳实践。当我实现新特性/功能时,我发现我同时处理多个文件、它们的示例和文档,这样我的 git status 可能会报告 15 个已更改的文件。但这些文件可能与项目的 3 个不同部分相关。
是否最好将它们分成 3 个单独的部分提交,将相关文件放在一起,以便我稍后可以返回并更轻松地找到这些提交。或者使用适当的消息一次性提交所有这些也同样容易吗?
This may not be a git specific question, but it comes up in the context of git. The idea may apply more broadly to other vcs's.
I am working on a small project in which I am currently the only developer. I'm getting used to using git, so I am wondering about best practices. As I implement new features/functions, I find that I work on multiple files, their examples, and documentation at once, such that my git status may report 15 files that have changed. But those files might relate to 3 different parts of the project.
Is it better to commit them in 3 separate parts, keeping the related files together, so that I could later go back and more easily find those commits. Or it is just as easy to commit them all at once with an appropriate message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好使提交成为原子的。也就是说,提交代表了对相关项目的一个逻辑更改,并且可以独立存在。
这使得
git bisect
能够正常工作Its preferable to make commits atomic. That is, a commit represents one logical change to the project in question, and can stand alone.
This allows
git bisect
to work correctly可以帮助您做出正确“数量”提交的一个标准是
git bisect
或git Blame
:当尝试使用git bisect
来检测一个大的提交时,是否会造成麻烦?漏洞?这就是“了解 Git 工作流程”博客文章的内容,它描述了“检查点” commits”(在不稳定状态下捕获代码的提交太少),或“no-ff commits”(表示在一次大型提交中捆绑在一起的修改过多)。
One criteria that can help you make the right "amount" of commit is
git bisect
orgit blame
: would a large commit be a nuisance when trying togit bisect
in order to detect a bug?That is what describes the "Understanding the Git Workflow" blog post, when it describes "checkpoint commits" (too little commits capturing the code in a unstable state), or "
no-ff
commits" (which represents too many modification bundled together in one large commit).这可能很困难,并且对于“最好的工作流程”有很多不同的看法。在可能的情况下,最好将
It can be difficult, and there are many differing views about "the one best workflow". Where possible it is better to
git stash
to partition which work you place in each commit.