Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a file using svn?

Tags:

svn

When I try svn mv old_file_name new_file_name, I get

 svn: Path 'new_file_name' is not a directory 

What's the correct way? (sorry, this seems so trivial, but I'm stuck).

PS. using svn version 1.6.11

EDIT it seems I get this error only if new_file_name refers to the name of a file that is currently under version control. In this case, of course, I can simply

 mv old_file_name new_file_name  svn delete old_file_name 
like image 401
Walter Avatar asked Jun 24 '13 16:06

Walter


People also ask

How do I change my name in svn?

In this case svn mv should work as follows: $ svn mv old_file_name new_file_name A new_file_name D old_file_name $ svn stat A + new_file_name > moved from old_file_name D old_file_name > moved to new_file_name $ svn commit Adding new_file_name Deleting old_file_name Committing transaction...

Can I rename a branch in svn?

Because branches and tags are ordinary directories, the svn move command can move or rename them however you wish.


1 Answers

The behaviour differs depending on whether the target file name already exists or not. It's usually a safety mechanism, and there are at least 3 different cases:

Target file does not exist:

In this case svn mv should work as follows:

$ svn mv old_file_name new_file_name A         new_file_name D         old_file_name $ svn stat A  +    new_file_name         > moved from old_file_name D       old_file_name         > moved to new_file_name $ svn commit Adding     new_file_name Deleting   old_file_name Committing transaction... 

Target file already exists in repository:

In this case, the target file needs to be removed explicitly, before the source file can be renamed. This can be done in the same transaction as follows:

$ svn mv old_file_name new_file_name  svn: E155010: Path 'new_file_name' is not a directory $ svn rm new_file_name  D         new_file_name $ svn mv old_file_name new_file_name  A         new_file_name D         old_file_name $ svn stat R  +    new_file_name         > moved from old_file_name D       old_file_name         > moved to new_file_name $ svn commit Replacing      new_file_name Deleting       old_file_name Committing transaction... 

In the output of svn stat, the R indicates that the file has been replaced, and that the file has a history.

Target file already exists locally (unversioned):

In this case, the content of the local file would be lost. If that's okay, then the file can be removed locally before renaming the existing file.

$ svn mv old_file_name new_file_name  svn: E155010: Path 'new_file_name' is not a directory $ rm new_file_name  $ svn mv old_file_name new_file_name  A         new_file_name D         old_file_name $ svn stat A  +    new_file_name         > moved from old_file_name D       old_file_name         > moved to new_file_name $ svn commit Adding         new_file_name Deleting       old_file_name Committing transaction... 
like image 129
nosid Avatar answered Sep 27 '22 22:09

nosid