In SVN, how do I copy just the subdirectories of a directory to another directory?

时光怂恿深爱的人放手 提交于 2019-12-06 18:20:18

问题


Via command line, I usually do this:

cp -rRp /path/to/a\_folder/. /path/to/another\_folder

This copies just the contents underneath a_folder to another_folder. In SVN I need to do the same thing, but can't figure it out. I always end up with this:

/path/to/another\_folder/a\_folder

SVN throws up even when I try this:

svn copy file:///path/to/a\_folder/* file:///path/to/another\_folder

It says it does not exist.

EDIT:

This would probably help. The directory structure for my project looks like this:

my_project
  /branches
  /tags
  /trunk
  /vendor
    /1.1

I need to get the contents of 1.1 under vendor into the trunk without it actually copying the 1.1 folder.


回答1:


Have you considered using svn merge?

Given a repo like this:

trunk/a_folder/foo
trunk/a_folder/bar
trunk/new_folder/baz

use these commands to merge the foo and bar directories:

cd trunk/new_folder
svn merge -r1:HEAD http://svn/repo/trunk/a_folder .



回答2:


As you've certainly discovered, copying to a target directory that already exists won't work:

svn cp svn://my_project/vendor/1.1 svn://my_project/trunk

because trunk already exists, so you'd end up with:

svn://my_project/trunk/1.1

Using merge has the unfortunate property of not keeping history of the vendor 1.1 tag in subversion prior to 1.5 which introduced merge tracking. You may not care. In this case merge would be the correct solution:

svn co svn://my_project/trunk trunk-wc
svn merge svn://my_project/trunk svn://my_project/vendor/1.1 trunk-wc

The best way to read this merge is: First determine the changes necessary to to make trunk identical to vendor/1.1, then apply those changes to the given working copy (also of trunk, in this case).

I should point out that this merge will effectively blow away anything that was in trunk previously. So, if you have local (non-vendor) modifications already on the trunk, you'll want to apply just the changes between 1.1 and the previous vendor drop:

svn co svn://my_project/trunk trunk-wc
svn merge svn://my_project/vendor/1.0 svn://my_prjoect/vendor/1.1 trunk-wc

If trunk exists, but is empty you've got two choices: replace the trunk, or write a little shell loop:

Replacing the trunk looks like this:

svn rm svn://my_project/trunk
svn cp svn://my_project/vendor/1.1 svn://my_project/trunk

Leveraging the shell (bash):

svn co svn://my_project/trunk trunk
svn co svn://my_project/vendor/1.1 1.1
( cd 1.1
  for x in * ; do
    svn cp $x ../trunk
  done 
)
svn ci trunk



回答3:


This link explains a workaround.

http://svn.haxx.se/users/archive-2004-12/1537.shtml

Basically what it says is that if the destination folder is not existing in the repo, you will get the contencts of your source folder in the destination folder.

See below example. The folder 07-03-2012 does not exist in your repo. Once you execute the below command, you will get the contents of HEAD folder in 07-03-2012.

svn cp <URL>/HEAD/ <URL>/branches/07-03-2012 -m "test"



回答4:


I think that what you want is that the contents of the trunk end up in the /tags/version-1.0/ folder without there being an extra /trunk folder there. i.e. This is bad: /tags/version-1.0/trunk/stuff. This is good: /tags/version-1.0/stuff.

To get this I do a 2 step process:

svn copy http://localhost/MyProject/trunk    http://localhost/MyProject/tags/

# now I have /MyProject/tags/trunk

svn rename http://localhost/MyProject/tags/trunk  http://localhost/MyProject/tags/version-1.0



回答5:


You're very, very close:

svn copy -m"Copy Directory" file:///path/to/a_folder file:///path/to/another_folder

just drop the /* from the first argument.



来源:https://stackoverflow.com/questions/260658/in-svn-how-do-i-copy-just-the-subdirectories-of-a-directory-to-another-director

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!