How to rename a file using svn?
Asked Answered
T

4

96

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
Tumble answered 24/6, 2013 at 16:4 Comment(1)
Maybe you need the full repository path, file://... or svn://... or http://... to the file.Wordy
P
125

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...
Prose answered 24/6, 2013 at 20:26 Comment(6)
I needed to add --force to svn rm new_file_name as it complained that new_file is is not under version control.Ionosphere
.. and I had to create an empty file called new_file_name.Ionosphere
on 1.8.3 rm removes the physical file, just running the "svn mv ..." was sufficient, it executes that A D.Friedrich
It is funny how old SVN is and how awkward it is to rename a file using it.Decarburize
@Ghasan: The title of the question might be misleading. It's about removing one file and renaming another file at the same time. This use case is not that common, and a bit tricky with most VCS, in particular if the information should be visible in the history.Prose
For me simply typing svn mv old_file_name new_file_name did the trick. Then I checked it with stat and committed it. (I was renaming a file, that already existed.) Very helpful, thank you.Antoniaantonie
O
18

Using TortoiseSVN worked easily on Windows for me.

http://tortoisesvn.net/

Right click file -> TortoiseSVN menu -> Repo-browser -> right click file in repository -> rename -> press Enter -> click Ok

Using SVN 1.8.8 TortoiseSVN version 1.8.5

Olli answered 26/3, 2014 at 18:33 Comment(6)
Not that the OP was asking about Windows, but upvotes deserve extension: Full desktop integration means that you may simply do this in the context menu from Explorer.Privily
But now I see that posting a Windows answer on what is clearly a Linux question has gotten this one down-voted several time. (drats, time ran out for me to edit my original comment)Privily
I was using Cygwin on Windows at the time, so there was some crossover.Olli
I couldn't get it to work without using TortoiseSVN on Windows. So I am thankful for this answer. I upvoted you. Using anything else kept causing it to revert anytime I updated. In my case the change was capitalization of the file names. I think the issue in my case stems from the fact that Windows is case insensitive.Manned
This worls, but you will lose the history of the file.Lw
Then, what happen with users that have old_file_name on their working copy?Davao
U
8

This message will appear if you are using a case-insensitive file system (e.g. on a Mac) and you're trying to capitalize the name (or another change of case). In which case you need to rename to a third, dummy, name:

svn mv file-name file-name_
svn mv file-name_ FILE_Name
svn commit
Unmoving answered 19/10, 2016 at 9:34 Comment(1)
And I was wondering why it works on Linux but not on Mac. Thanks!Putup
L
0

It can be if you created new directory at the disk BEFORE create/commit it in the SVN. All that you need is just create it in SVN and do move after:

$ svn mv etc/nagios/hosts/us0101/cs/us0101ccs001.cfg etc/nagios/hosts/us0101/ccs/
svn: E155010: Path '/home/dyr/svn/nagioscore/etc/nagios/hosts/us0101/ccs' is not a directory

$ svn status
?       etc/nagios/hosts/us0101/ccs

$ rm -rvf etc/nagios/hosts/us0101/ccs
removed directory 'etc/nagios/hosts/us0101/ccs'

$ svn mkdir etc/nagios/hosts/us0101/ccs
A         etc/nagios/hosts/us0101/ccs

$ svn move etc/nagios/hosts/us0101/cs/us0101ccs001.cfg etc/nagios/hosts/us0101/ccs/us0101accs001.cfg
A         etc/nagios/hosts/us0101/ccs/us0101accs001.cfg
D         etc/nagios/hosts/us0101/cs/us0101ccs001.cfg

$ svn status
A       etc/nagios/hosts/us0101/ccs
A  +    etc/nagios/hosts/us0101/ccs/us0101accs001.cfg
        > moved from etc/nagios/hosts/us0101/cs/us0101ccs001.cfg
D       etc/nagios/hosts/us0101/cs/us0101ccs001.cfg
        > moved to etc/nagios/hosts/us0101/ccs/us0101accs001.cfg
Lanlana answered 8/6, 2018 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.