简体   繁体   English

使用版本控制很好地重构

[英]Refactoring Nicely with Version Control

A co worker of mine asked me to review some of my code and he sent me a diff file. 我的一个同事让我查看我的一些代码,他给我发了一个差异文件。 I'm not new to diffs or version control in general but the diff file was very difficult to read because of the changes he made. 我不是一般的差异或版本控制的新手,但由于他所做的改变,差异文件很难阅读。 Specifically, he used the "extract method" feature and reordered some methods. 具体来说,他使用了“提取方法”功能并重新排序了一些方法。 Conceptually, very easy to understand but looking at the diff, it was very hard to tell what he had done. 从概念上讲,很容易理解,但看到差异,很难说出他做了什么。 It was much easier for me to checkout the previous revision and use Eclipse's "compare" feature, but it was still quite clunky. 我更容易检查以前的版本并使用Eclipse的“比较”功能,但它仍然非常笨重。

Is there any version control system that stores metadata related to refactoring. 是否有任何版本控制系统存储与重构相关的元数据。 Of course, it would be IDE and Programming Language specific, but we all use Eclipse and Java! 当然,它将特定于IDE和编程语言,但我们都使用Eclipse和Java! Perhaps there might be some standard on which IDEs and version control implementations can play nicely? 也许可能有一些标准可以让IDE和版本控制实现很好地发挥作用?

Eclipse can export refactoring history (see 3.2 release notes as well). Eclipse可以导出重构历史记录 (请参阅3.2发行说明 )。 You could then view the refactoring changes via preview in Eclipse. 然后,您可以通过Eclipse中的预览查看重构更改。

I don't know of compare tools that do a good job when the file has been rearranged. 我不知道比较工具在重新安排文件时做得很好。 In general, this is a bad idea because of this type of problem. 一般来说,由于这类问题,这是个坏主意。 All too often people do it to simply meet their own style, which is a bad, bad reason to change code. 人们经常这样做只是为了满足自己的风格,这是改变代码的一个坏的,坏的理由。 It can effectively destroy the history, just like reformatting the entire file, and should never be done unless necessary (ie it is already a mess and unreadable). 它可以有效地破坏历史记录,就像重新格式化整个文件一样,除非必要,否则永远不应该完成(即它已经是混乱且不可读)。

The other problem is that working code will likely get broken because of someones style preferences. 另一个问题是,由于某些人的风格偏好,工作代码可能会被破坏。 If it ain't broken, don't fix it! 如果没有损坏,请不要修理它!

I asked a similar question a while ago and never did get a satisfactory answer. 我刚才问了一个类似的问题 ,从来没有得到满意的答案。 I'll be watching your question to see what people come up with. 我会看着你的问题,看看人们想出了什么。

For your particular situation, it might be best to review the latest version of the file, using the diff as a guide. 对于您的特定情况,最好使用diff作为指南来查看文件的最新版本。 That's what I have been doing in my situation too. 这也是我在我的情况下一直在做的事情。

The Refactoring History feature is new to me, but I like the way it sounds. 重构历史功能对我来说是新的,但我喜欢它听起来的方式。 For a less tool-specific method, I like sending patch files. 对于特定于工具的方法,我喜欢发送补丁文件。 The person reviewing just applies the patch and reviews the results, and then they can revert to the version in version control when they're done. 审阅人员只应用补丁并审查结果,然后他们可以在完成后恢复到版本控制中的版本。

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

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