如何找到版本控制系统中的某些更改?

发布于 2025-01-05 03:08:04 字数 724 浏览 0 评论 0原文

我不知道我这里是否触及了一个微妙的主题,至少看起来并不容易……

有很多VCS 那里有更多的帖子/博客/...描述它们的效率。还有很多建议可以在不需要时从代码中删除内容(干净的代码)。总是有这样的句子:“无论如何它都不会丢失”,“你总是可以回到它”,......

我不太明白。假设有几个开发人员正在开发一个特定项目。新的需求出现在场景中,导致创建、修改和删除代码。并希望重构。

实际上,偶尔会发生需要某个功能,然后删除然后重新添加的情况。换句话说,代码已经写好了。该代码是在“必需”阶段编写的,并在“不再”阶段删除的。 “重新添加”阶段会发生什么?有些人可能建议重写代码,但我不认为这是一个选择。实际上,“旧”代码可能包含对当时出现的问题的修复。

这个项目不小,很多类,很多逻辑,也许还有一些人事变动,你明白了。恕我直言,总是期望至少一名开发人员记住编写过的代码以及代码发生的位置(包括分支名称)是不公平的。

VCS 是否有任何支持来回答诸如“

  • 尚未删除的特定方法在哪里,我对其名称只有一个模糊的猜测”之类的问题?
  • 我很确定这里有一个 if 语句,但是它发生了什么?
  • ...

我不想将这个问题限制在一个 VCS 上。这应该是一个更普遍的问题。如果有人关心的话,我们目前使用 Mercurial。

I don't know if I touch a delicate subject here, at least it doesn't seem to be easy...

There are many VCS out there, plenty more posts/blogs/... describing how efficient they are. And there are also many suggestions to remove stuff from the code when it isn't needed (clean code). There are always sentences like "it doesn't get lost anyway", "you can always get back to it", ...

I can't quite follow that. Let's say there a few developers working on one particular project. New requirements appear on the scene resulting in creating, modifying and deleting code. And hopefully refactoring.

In reality it happens occasionally that a certain feature is required, then dropped and then re-added later. In other words there was code written already. That code got written during the "required" phase and got removed during the "not any more" phase. What happens in the "re-added" phase? Some may suggest to rewrite the code, but I don't consider that an option here. Actually the "old" code might include fixes for problems that arose back then.

The project isn't small, many classes, plenty of logic, maybe some personnel changes, you get the idea. IMHO it's not fair to always expect from at least one developer to remember that there was code written and where it happened (including branch names).

Is there any support from a VCS to answer questions like

  • Where was a yet removed particular method and I only have a vague guess about its name?
  • I'm pretty sure that there was an if-statement right here, but what happened to it?
  • ...

I don't want to restrict this question to one VCS. It should be more of a general question. If anyone cares, we currently use Mercurial.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

与之呼应 2025-01-12 03:08:04

这是最好处理的一种场景:

  • 许多功能分支
  • 要合并到一个合并分支(或 恢复(如果您不想再合并某个功能))应在下一个版本中使用的所有功能,以便执行集成测试。

(如“什么是有用的分支版本控制策略中所述?< /a>")

使用 DVCS(Mercurial、Git)更容易做到这一点,因为您可以轻松地将一个分支中的一组提交合并/rebase/cherry-pick 到另一个,而且还取消您不想看到的提交


现在关于“查找内容”:

由于 DVCS 中的修订往往比 CVCS 中的修订要小,因此您最终会在自己的提交中分离出“小内容”,您可以稍后返回并查看它们是否已合并。

使用 DVCS 还更容易的是:

  • 通过连贯的更改集保持清晰的历史记录(因为您可以重新安排提交,将它们拆分或合并在一起),这改善了获取井中隔离的特定修改的变化已识别的提交(并且不与同一修订版中的其他更改混合),
  • 在提交中查找特定内容

This is the kind of scenario best handled with:

  • many feature branches
  • one consolidation branch in which you are merging (or reverting if you don't want anymore a feature merged) all the features that should make it for the next release, in order to perform integration tests.

(as described in "What is a useful Branch Versioning Strategy?")

This is easier to do with DVCS (Mercurial, Git), in that you can easily merge/rebase/cherry-pick a set of commit from one branch to another, but also canceling commits you don't want to see.


Now about "finding stuff":

Since revisions in a DVCS tend to be smaller than in a CVCS, you end up with the "small things" isolated in their own commit that you can get back later and see if they have been merged or not.

What is also easier with a DVCS is:

  • keeping a clear history with coherent change sets (since you can re-arrange commits, splitting them or merging them together), which improves the change of getting back a particular modification isolated in a well identified commit (and not mixed with other changes in the same revision),
  • finding a specific content within commits.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文