Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch back to a previous version of a file without deleting its subsequent revisions?

Tags:

svn

I have 4 versions of file A.txt in my subversion repository, say: A.txt.r1, A.txt.r2, A.txt.r3 and A.txt.r4. My working copy of the file is r4 and I want to switch back to r2. I don't want to use "svn update -r 2 A.txt" because this will delete all the revisions after r2, namely r3 and r4.

So is there any way that I update my working copy to r2 and still having the option to switch to r3 and r4 later? Put it another way, I want to still be able to see all 4 revisions by using "svn log A.txt" after doing the update.

like image 570
Martin08 Avatar asked Sep 18 '08 16:09

Martin08


7 Answers

To make a new revision of A.txt that is equal to revision 2:

svn up -r HEAD
svn merge -r HEAD:2 A.txt
svn commit

Also see the description in Undoing changes.

like image 73
Bruno De Fraine Avatar answered Oct 05 '22 03:10

Bruno De Fraine


The command svn up -r 4 only updates your local copy to revision 4.

The server still has all versions 1 through to whatever.

What you want to do, is create a new revision, revision number 5, which is identical to revision number 2.

cd /repo 
svn up -r 2 
cp /repo/file /tmp/file_2 
svn up -r 4 
cp /tmp/file_2 /repo/file 
svn commit -m "Making 5 from 2" 

If you ever change your mind and want 4 back, you can do so by creating revision 6 from revision 4.

cd /repo 
svn up -r 4
cp /repo/file /tmp/file_4
svn up -r 5 
cp /tmp/file_4 /repo/file 
svn commit -m "Making 6 from 4" 

Happy hacking.

( there is of course a way to do the above in only 2 commands i believe, but its been a while since I did it and it can be a little confusing )

like image 37
Kent Fredric Avatar answered Oct 05 '22 02:10

Kent Fredric


I don't have a lot of experience with Subversion so please excuse me if this method doesn't work in this environment.

In this situation I follow these steps:

  1. Check out the file in question ready for editing as r4
  2. Overwrite your local copy of the file with the revision you require, in this case r2
  3. Check in / commit this "new" revision of the file as r5 with an appropriate comment

This way when you go through your file history you will see something like:

  • r1
  • r2
  • r3
  • r4
  • r5 (comment: "reverted to r2 content")
like image 45
Adrian Clark Avatar answered Oct 05 '22 02:10

Adrian Clark


svn update -r 2 A.txt

This command will not delete any versions in the repository. It will set your working copy of A.txt to be revision 2. You can see this by doing

> svn status -u A.txt
  *     2   A.txt

The output of this command show that you are viewing version 2, and that there are updates (that's the *).

After doing this update, you will still be able to do "svn log" and see all the revisions.

Performing "svn update A.txt" will return you to the latest version (in your case, r4).

like image 42
jgindin Avatar answered Oct 05 '22 01:10

jgindin


updating to an older rev will not delete your newer revs.

so you could do svn up -r2 file, then svn up -r4 file.

also, you wouldn't be able to commit the r2 file this way, because you'd have to update before committing, and you'd end up with r4 again.

like image 40
kch Avatar answered Oct 05 '22 03:10

kch


"I don't want to use "svn update -r 2 A.txt" because this will delete all the revisions after r2, namely r3 and r4."

Uh... it won't, actually. Try it: do a regular svn update after the -r 2 one and you'll see the working copy updated back to r4.

like image 30
moonshadow Avatar answered Oct 05 '22 01:10

moonshadow


Update won't delete any revisions on the server. The only changes it makes are to your local working copy:

SVN Update Command

"brings changes from the repository into your working copy"

"synchronizes the working copy to the revision given by the --revision switch"

like image 30
Tim Erickson Avatar answered Oct 05 '22 02:10

Tim Erickson