Revert a file on SVN repository but keep local version
Asked Answered
T

5

7

I accidentally 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.

Thump answered 21/6, 2010 at 20:2 Comment(0)
E
10

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.
Eudemonics answered 21/6, 2010 at 20:5 Comment(3)
This is completely unpractical if the change affects more than a few files.Dairen
Konrad's solution below is better because it uses basic svn commands rather than hacking together a solution.Lubber
Step 1 can be done for several files at a time: in the revision log dialog, select the files in the bottom pane and click on Export in the context menu. The files will be exported in their directory tree.Definitive
V
2

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.

Viminal answered 21/6, 2010 at 20:4 Comment(0)
D
1

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.

Dairen answered 4/1, 2019 at 11:1 Comment(1)
This should be the accepted answer as it leverages the power of svn instead of hacking together a solution.Lubber
P
0

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.

Pilpul answered 21/6, 2010 at 20:5 Comment(0)
D
0

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.
Dejecta answered 22/6, 2010 at 1:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.