4

Let's assume I work on a C program file which has 10 functions. During one review, I changed their return types, return values and I added some checks/documentation. After some time I realize that while the checks and the documentation I added are fine, I shouldn't modify the return types. And this goes to the folowing, more general question?

Is there any way to explore the undo tree and select the modifications that I want?

Gundo seems very close to what I want. The interface is ideal, as I have a diff view and a browser view of the modifications I made. But is there a way to go to a certain state and select the updates that I want to keep?

  • Changes to the file are incremental, not independent. I think the best you can do is look at the diff with Gundo and sort of manually apply that portion of the change state. – tommcdo Jul 24 '15 at 3:39
4

The gundo plugin has a preview window, where it shows the diff between the selected version and the previous one. You can locate the relevant changes in the change tree, then go to the preview window, save the buffer to a patch file, then edit the file to keep the relevant changes, then reverse the patch. Something like diff-fold and / or patchutils can make your life easier when editing the patch.

2

One way to approach this might be to diff the two versions of the file.

Before we can diff we first write a copy of the current state, and then undo to the initial state.

:w over_developed.c
999u
:vert diffsplit over_developed.c

(To diff in "the other direction" you could undo, write a copy, redo, then open the diff.)

You can then navigate to those lines in over_developed.c that you want to retain, and hit dp to push them into the real file.

Unfortunately dp might not work in this precise case, because it groups lines together, and it sounds like you might have multiple changes on a single line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.