Reverting single file in SVN to a particular revision

前端 未结 14 1838
生来不讨喜
生来不讨喜 2021-01-29 18:09

I have a file as shown below in an SVN repo that I would like to revert to a previous version. What is the way to do this in SVN? I want only downgrade this particular file to a

相关标签:
14条回答
  • 2021-01-29 18:55

    So far all answers here seem to have significant downsides, are complicated (need to find the repo URI) or they don't do what the question probably asked for: How to get the Repo in a working state again with that older version of the file.

    svn merge -r head:[revision-number-to-revert-to] [file-path] is IMO the cleanest and simplest way to do this. Please note that bringing back a deleted file does not seem to work this way[1]. See also the following question: Better way to revert to a previous SVN revision of a file?

    [1] For that you want svn cp -r [rev-number] [repo-URI/file-path]@[rev-number] [repo-URI/file-path] && svn up, see also What is the correct way to restore a deleted file from SVN?

    0 讨论(0)
  • 2021-01-29 18:56

    For a single file, you could do:

    svn export -r <REV> svn://host/path/to/file/on/repos file.ext

    You could do svn revert <file> but that will only restore the last working copy.

    0 讨论(0)
  • 2021-01-29 18:57

    If you just want the old file in your working copy:

    svn up -r 147 myfile.py
    

    If you want to rollback, see this "How to return to an older version of our code in subversion?".

    0 讨论(0)
  • 2021-01-29 19:00

    You want to do

    svn merge -r [revision to revert from]:[revision to revert to] [path/filename]

    Once you do that, you will have that revision of the file in a committable state. Commit the file.

    0 讨论(0)
  • 2021-01-29 19:01

    If it's only a couple of files, and if you're using Tortoise SVN, you can use the following approach:

    1. Right click on your source file, and select "TortoiseSVN" -> "Show log".
    2. Right click on a revision in the log, and select "Save revision to...".
    3. Let the old revision overwrite your current file.
    4. Commit the overwritten source file.
    0 讨论(0)
  • 2021-01-29 19:04

    I found it's simple to do this via the svn cat command so that you don't even have to specify a revision.

    svn cat mydir/myfile > mydir/myfile
    

    This probably won't role back the inode (metadata) data such as timestamps.

    0 讨论(0)
提交回复
热议问题