使用 dvcs/git,单个提交是否优于多个小型主题提交?

发布于 2024-11-30 04:44:24 字数 291 浏览 0 评论 0原文

这可能不是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

画尸师 2024-12-07 04:44:24

最好使提交成为原子的。也就是说,提交代表了对相关项目的一个逻辑更改,并且可以独立存在。

这使得

  1. 简单的代码检查
  2. 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

  1. Easy code inspection
  2. git bisect to work correctly
情仇皆在手 2024-12-07 04:44:24

可以帮助您做出正确“数量”提交的一个标准是 git bisectgit Blame:当尝试使用 git bisect 来检测一个大的提交时,是否会造成麻烦?漏洞?

这就是“了解 Git 工作流程”博客文章的内容,它描述了“检查点” commits”(在不稳定状态下捕获代码的提交太少),或“no-ff commits”(表示在一次大型提交中捆绑在一起的修改过多)。

One criteria that can help you make the right "amount" of commit is git bisect or git blame: would a large commit be a nuisance when trying to git 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).

梦归所梦 2024-12-07 04:44:24

这可能很困难,并且对于“最好的工作流程”有很多不同的看法。在可能的情况下,最好将

  1. 关注点分开——使用许多短期的独立分支,每个关注点一个。您始终可以在最终合并并发布到更高级的分支之前压缩提交序列。
  2. 经常提交 - 较小的步骤可以更轻松地找到发生错误的位置和原因,并调整合并。再次发挥作用后,您可以挤压它。
  3. 使用暂存区域和 git stash 来划分您在每次提交中放置的工作。
  4. 不要太担心轻微的失误。只有倒着走才能有远见。

It can be difficult, and there are many differing views about "the one best workflow". Where possible it is better to

  1. separate concerns - use a number of short lived separate branches, one per concern. You can always squash your commit sequence before the final merge and publishing to a more senior branch.
  2. commit often - smaller steps make it easier to find where mistakes happened and why, and to align merges. Again you can squash after it works.
  3. use the staging area and git stash to partition which work you place in each commit.
  4. Don't worry too much about minor slip ups. Foresight only happens if you walk backwards..
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文