This is a question for SuperUser more than StackOverflow.
However, the answer is that it's only possible if the software stores the history of change steps to the saved file. Most common interchangeable image formats, like the JPG example in your question, do not support storage of that information.
An image editor could save to a format, likely to be specific to the editor, which preserves the history of alterations to the image. However, this could lead to a lot of storage of data that is usually not useful in the future, so there isn't a huge amount of demand for the feature.
Note that what is sought in the question could be done by a new operation to erase the line or parts of it, but not as an undo operation from the prior editing session.