0

Use case. I have committed a file with many changes, and I forgot to make a new commit for a much smaller side-task - to clean the file from some personal outdated e-mails I found in there, which has nothing to do with the bigger task. To keep the git workflow clean, that cleanup of e-mails should have been in a second commit instead. I now need to split up the one commit into two commits, which means splitting up the code change as well.

In codium/vscode, in the Source Control pane,

enter image description here

in the COMMIT tab,

enter image description here

I choose the file (server.py) in which I need to get back a few "wrong" lines back with the wrong personal e-mail in it. I can see a sort of visualized git diff between the old and the new file (before and after the latest commit).

enter image description here

Now I do not want to copy and paste the wrong e-mail back from the "old file" to the working file.

Is there a way to change back (undo, redact, unstage, not sure what is the best word here) a commit only for a chosen line using the git functions of codium/vscode?

1 Answer 1

0

No tool for this up to now, but may become a feature in the future?

You do not seem to be able to do this line by line - that would be possible only if you had conflicts, at best using the nice vscode workbench with its 3 way merge editor since release 1.69.0 (June 2022 release). That editor cannot remove lines with a conflict and by the same time add those removed lines to a new file, though, and that is what would be needed here.

Workaround

Make a new commit after the root commit that has only the small changes and that comes right before the "full file commit". If you then go to the follow-up commit with the full file, the small changes have already been made. This is not even a workaround since this was clear from the start of the question, but there seems to be no other answer: you will have to go through all of the small changes and make a new small commit of them. Which can be quite some work if it is not just about some automatic style changes, but various email changes that you would need to check each by each, like in this case.

To make this step just slightly easier, you might still merge the full file and the root file by means of the 3 way merge editor. You would then add the small changes by hand with copy and paste from the full file above into the third window below the two (= your new "small commit") and save the third window as a new file in the end.

This screenshot is not what is meant here, since it is working on a line that has conflicts, but it shows that you can change things by hand in the file window below:

enter image description here

Idea

To make it clear what would be needed here as an answer, taking the workbench with its 3 way merge editor, you would have a third/fourth checkbox (one for each side) that would undo the step in the chosen file to what the root commit had, and then would save the undone step to a new third file that would then have the undone commit line in it. Thus, not just this 3 way merging step (as follows), but also a 3 way splitting step.

This is not in the tool up to now:

enter image description here

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .