I acc开发者_运维知识库identally committed some changes to the repository that were not complete. I do not want to lose my local changes, but i want to revert the file in the repository to where i was before i committed the changes.
Not sure if there is a feature to do this. But what I would do is
- Take your file and copy it into a separate directory [like on your desktop].
- In your SVN directory, revert
that specific file to the
previous version. - Commit that version so it's now the HEAD version.
- Get your file from the desktop
and copy it back in, and
overwrite it and don't check it
in.
The only choice is to backup your changes then do the reverse merge on the server then copy your changes back into your working copy.
Short of editing the upstream repository’s history (which you can do but shouldn’t, in this case), the following is the simplest way of achieving this:
- Undo changes locally
- Commit undone changes
- Redo changes locally
Let’s assume the accidental commit was $REV
(you can use svnversion
or svn log
to find out). Then do the following:
svn merge -c -$REV .
svn ci -m "Revert r$REV"
The last line of the last command gives you the new revision number:
Committed revision $NEW_REV.
Use that below to recover your changes locally:
svn up # Necessary if your repository has mixed revisions (e.g. due to externals).
svn merge -c $NEW_REV .
(Usually $NEW_REV
should simply be $REV
+ 1.)
Done.
I would recommend saving the specific files you committed to an external folder. Then revert the file in the repository and commit. Thereby resulting in the state from before you committed. Then take the files you saved and replace them so your copy has your local changes.
Use the "switch" command in SVN. It's easy, and a trick worth knowing.
- If this is your first time, copy the whole directory somewhere safe, or use WinZip (use option to preserve directory structure).
- In your private branch (you DO have a private branch, right? If not, make one), make a copy of the branch in question, using the repository browser.
- Do a "switch" on your PC (called "switch" in TortoiseSVN) to point your local folder to the private branch.
- Check it in.
- Switch back to the original branch.
- Revert.
精彩评论