Thursday, April 2, 2015

Reverting accidental SVN Checkins

The one thing I want from TortoiseSVN is a confirmation message whenever I am commiting my changes.  Sometimes, I use "SVN Commit..." option to see which files were changed and accidentally, I hit "Ok" instead of "Cancel".   If you're in the same boat, read on.

If you accidentally checked in the files that are not supposed to be, you need to revert that revision and bring your local code back to the same set of files that must be in the "Changed" state.  Follow these steps for the result:


  1. Create a new local folder.
  2. Get the latest code from the branch where the files are accidentally checked in.
  3. Right click on the local folder and select "Tottoise SVN...Show Log". This will show the revisions including the one you had accidentally checked in.
  4. Right click the revision below the one you last checked in.
  5. Choose "Revert to this revision" option.
  6. This will cancel all the changes that were checked in the "accidental" version in your local copy.
  7. Right click on the new local folder and select "SVN Commit..." to commit the reverted changes.
  8. To bring back your changes to the local folder, see the next section "Bringing back the changes to the local version".



Bringing back the changes to the local version

  1. Go back to the root of the folder where the "accidental" check in happened.
  2. Right click and "Tortoise SVN...Show Log".
  3. Click the revision  you checked in accidentally and the revision below that.
  4. Right Click and select "Show differences as unified Diff".  This will show all the changes you did.
  5. Click "File" and save it as a patch.
  6. In the root of the folder, right click and "Svn Update"
  7. It will bring the latest version (which had been checked in after cancelling out your changes).
  8. Right click on the root folder and select "Tortoise SVN...Apply Patch..." option.
  9. Select the patch file you created in 5).
  10. Select "Patch All Items" option.
  11. Your changes should now be available in the local branch.