Reverting single file in SVN to a particular revision

前端 未结 14 1837
生来不讨喜
生来不讨喜 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:40
    svn revert filename 
    

    this should revert a single file.

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

    The best way is to:

    svn merge -c -RevisionToUndo ^/trunk
    

    This will undo all files of the revision than simply revert those file you don't like to undo. Don't forget the dash (-) as prefix for the revision.

    svn revert File1 File2
    

    Now commit the changes back.

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

    surprised no one mentioned this

    without finding out the revision number you could write this, if you just committed something that you want to revert, this wont work if you changed some other file and the target file is not the last changed file

    svn merge -r HEAD:PREV file
    
    0 讨论(0)
  • 2021-01-29 18:47

    If you want to roll back an individual file from a specific revision and be able to commit, then do:

    svn merge -c -[OldRev#] [Filename]

    ie. svn merge -c -150 myfile.py

    Note the negative on the revision number

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

    An alternate option for a single file is to "replace" the current version of the file with the older revision:

    svn rm file.ext
    svn cp svn://host/path/to/file/on/repo/file.ext@<REV> file.ext
    svn ci
    

    This has the added feature that the unwanted changes do not show up in the log for this file (i.e. svn log file.ext).

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

    Just adding on to @Mitch Dempsy answer since I don't have enough rep to comment yet.

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

    Adding the --force will overwrite the local copy with the export and then you can do an svn commit to push it to the repository.

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