如何撤销/重做代码的选择性部分? [英] How to undo / redo selective parts of code?

查看:130
本文介绍了如何撤销/重做代码的选择性部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse。



当我们开发这样的代码时,会发生很多事情(假设它是按顺序开发的,从上到下):

 第1部分(*)
第2部分
第3部分
第4部分(*)
第5部分

但是我们只是弄清楚第1和第4部分(用(*)标记)是错误的,其他的都很好。问题是我们如何才能撤消这两个部分(1和4),而不会撤消其余部分?



如果我们可以有选择地撤消,那太好了。请注意,将代码简单地还原到版本1会丢失部分2,3和5,这是正确的部分,应该保留在代码中。还要注意,通常这些部分混合在一个或两个代码块中(不在单独的块中)。



示例:

 第1部分:添加方法f1(x,y)并将一些代码从main()移动到f1() - >不正确(应该还原)
第2部分:添加方法f2(a,b,c,d) - >正确(应该保留)
第3部分:更改main()实现的另一部分 - >正确(应保留)
第4部分:将f2签名更改为f2(s,n) - >不正确(应该还原)
第5部分:更改f2的主体 - >正确(应该保留)

我使用的当前方法是:


  1. 将最新版本的副本保存在某处(例如,在临时的
    文本文件中),然后在第1部分之前撤消,并添加正确的零件
    从临时文本文件到源代码。

  2. 手动比较不同版本,解决冲突。

有没有人会想到更简单,更自动的方式来选择哪些更改可以撤消,哪一个要保留?

解决方案

我刚刚发现这篇论文:



支持代码编辑器中的选择性撤消,将在ICSE 2015中提供



作者以图形方式显示更改的历史记录,因此您可以选择要撤消的更改(以及要保留哪些更改)。



Azurite(可以从这里下载并安装)是它们实现的Eclipse插件的名称,它支持选择性的撤消和许多对开发人员有用的其他简单的功能。


I am using Eclipse.

It happens a lot when we develop code like this (assume it is developed sequentially, from top to bottom):

Part 1 (*)
Part 2
Part 3
Part 4 (*)
Part 5

But we just figured out that parts 1 and 4 (marked with (*)) are wrong and the others are just fine. The question is that how we can undo just those two parts (1 and 4) without undoing the rest?

If we could undo selectively, it was great. Note that simply reverting the code to the version 1 loses parts 2, 3 and 5 which are correct parts and should remain in the code. Also note that usually these parts are mixed in one or two code blocks (not in separate blocks).

Example:

Part 1: Add method f1(x, y) and move some code from main() to f1() --> incorrect (should be reverted)    
Part 2: Add method f2(a, b, c, d) --> correct (should remain)    
Part 3: Change another part of main() implementation --> correct (should remain)       
Part 4: Change f2 signature to f2(s, n) --> incorrect (should be reverted)       
Part 5: Change body of f2 --> correct (should remain)

The current approach I use is:

  1. Keeping a copy of the latest version somewhere (e.g., in a temporary text file), then undo to before part 1, and add those correct parts from the temporary text file to the source code.
  2. Manual comparison of different versions, and resolving conflicts.

Does anybody think of easier, yet more automatic way of selecting which change to undo and which one to keep?

解决方案

I just found this paper:

Supporting Selective Undo in a Code Editor which will be presented in ICSE 2015 conference.

The authors show the history of changes graphically, so you can choose which changes to undo (and which one to keep).

Azurite (can be download and installed from here) is the name of their implemented Eclipse plugin that supports selective undo and lots of other simple features that are useful for developers.

这篇关于如何撤销/重做代码的选择性部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆