I often notice a few unwanted changes when I review my working copy (with hg status
and hg diff
) right before a commit. For example, I might have temporarily added or remove some code just for the duration of a debugging session.
I know I can use hg revert
to remove unwanted changes, but this removes all the changes in the entire file. Is there a way to revert just a part of a file?
One way is using a graphical diff tool like kdiff3
. If you feed it the diff and choose "merge current file" you can go line by line and pick what you want.
The better way is to commit more often. If you make a habit to commit right before adding debugging code, then either commit or revert your debug code before adding your "real" code, it makes it very easy to remove your debug code because it has its own revision. Alternately, you can put your debugging code in a separate branch altogether.