While coding I added print statements into some files to keep track of what was going on.
When I am done, is it possible to revert changes in some files, but commit the file I actually worked on?
Say I added print in file A, but I modified file B. B is what I want to commit and A, I want to be set back to its old state.
There are three basic ways to do this depending on what you have done with the changes to the file A. If you have not yet added the changes to the index or committed them, then you just want to use the checkout command – this will change the state of the working copy to match the repository:
If you added it to the index already, use reset:
If you had committed it, then you use the revert command:
If on the other hand, you had committed it, but the commit involved rather a lot of files that you do not also want to revert, then the above method might involve a lot of “reset B” commands. In this case, you might like to use this method:
Another method again, requires the use of the rebase -i command. This one can be useful if you have more than one commit to edit: