开发者

Revert a file on SVN repository but keep local version

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

  1. Take your file and copy it into a separate directory [like on your desktop].
  2. In your SVN directory, revert that specific file to the
    previous version.
  3. Commit that version so it's now the HEAD version.
  4. 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:

  1. Undo changes locally
  2. Commit undone changes
  3. 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.

  1. If this is your first time, copy the whole directory somewhere safe, or use WinZip (use option to preserve directory structure).
  2. 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.
  3. Do a "switch" on your PC (called "switch" in TortoiseSVN) to point your local folder to the private branch.
  4. Check it in.
  5. Switch back to the original branch.
  6. Revert.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜