How to undo / redo individual parts of the code?

I am using Eclipse.

This happens very often when we develop such code (suppose that it develops sequentially, from top to bottom):

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

But we just realized that parts 1 and 4 (marked with (*)) are wrong, and the rest are just beautiful. The question is, how can we cancel only these two parts (1 and 4) without canceling the rest?

If we could cancel selectively, it was great. Note that simply returning the code to version 1 loses parts 2, 3, and 5, which are the correct parts and must 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'm using is:

  • Save a copy of the latest version somewhere (for example, in a temporary text file), then undo the action to part 1 and add these correct parts from the temporary text file to the source code.
  • Manually comparing different versions and resolving conflicts.

Does anyone think of an easier but more automatic way of choosing which changes to undo and which to save?

+1
source share
2 answers

I just found this article:

Support for selective cancellation in the code editor , which will be presented at the ICSE 2015 conference.

The authors display the history of changes graphically, so you can choose which changes to discard (and which one to save).

Azurite (you can download and install from here ) is the name of the embedded Eclipse plugin that supports selective disabling and many other simple features that are useful for developers.

+1
source

Eclipse keeps a history of your changes for several days (configured in the settings under "General"> "Workspace"> "Local History"). You can right-click on the file and select Compare s> Local History to see the differences between the two versions of your file. You can copy changes from the old version to the current version.

In the long run, you should use a version control system such as SVN or GIT. For them there are Eclipse plugins that allow you to perform similar operations "Compare with", but cover the entire history of the file (provided that you arbitrarily make your changes).

+2
source

All Articles