Svn只有一个子目录的Git [英] Svn to Git of only one subdirectory
问题描述
我知道git-svn,并用它将SVN存储库迁移到Git中。
有了一个回购协议,我有一个具体的要求,我找不到解决方案。该SVN回购包含多个实际项目作为子目录:
trunk /
project1 /
project2 /
project3 /
branches /
branch1 /
project1 /
project3 /
project2 /
...
等等...
我想要做的是将每个这些子项目自己在git中进行回购 - 显然,保留修订历史记录,分支,提交消息,标记等。
我可以使用 - ignore-paths
和 --include-paths
一次只能切换其中一个子项目,但它们会仍然出现在相应的 project1
等子目录下。我真正想要结束的是每个分支(包括trunk)中的项目
的内容。
有没有办法做到这一点?
我找到了解决方案。它并不像 git svn clone
那么简单,但并不难。所以,这就是我所做的(例如,对于问题场景中的 project1
):
- 在git服务器上为
project1
- 创建一个空的repo将空的repo克隆到本地机器上:
git clone git@git.server.com:group / project1.git
- 进入该空白回购工作目录:
cd project1
- 初始git svn回购:
git svn init --stdlayout --no-metadata https://svn.server.com/group
-
现在,这里是魔术来了。如果此时我运行
git config --local --list
,我会得到以下内容(仅显示相关行):
svn-remote.svn.fetch = trunk:refs / remotes / trunk
svn-remote.svn.branches = branches / *:refs / remotes / branches / *
svn-remote.svn.tags = tags / *:refs / remotes / tags / *
现在我需要做的只是在
git config --local --edit
中添加project1
正确的地方:
svn-remote.svn.fetch = trunk / project1:refs / remotes / trunk
svn- remote.svn.branches = branches / * / project1:refs / remotes / branches / *
svn-remote.svn.tags = tags / * / project1:refs / remotes / tags / *
-
现在您可以
git svn fetch
-
设置分支和标签:
用于`git branch中的分支-r | grepbranches /| sed's / branches\ ///'`;做
git分支$分支refs /远程/分支/ $分支
完成
在`git branch中标记-r | greptags /| sed's / tags\ ///'`;做
git标签-a -m转换SVN标签$ tag refs / remotes / tags / $ tag
done
-
最后将其全部推送到远程:
git push - 所有来源
git push - 标签来源
现在如果你克隆你的repo,你会在你的克隆的repo的根目录下得到 project1
的内容 - 正是我在找的东西。
I know about git-svn and have used it to migrate SVN repositories into Git.
With one repo I have a specific requirement, which I can't find a solution for. That SVN repo contains multiple actual projects as subdirectories:
trunk/
project1/
project2/
project3/
branches/
branch1/
project1/
project3/
project2/
...
and so on...
What I want to do is import each of these "sub-projects" in its own repo in git - obviously, keeping revision history, branches, commit messages, tags, etc.
I can use --ignore-paths
and --include-paths
switches to only pull one of these sub-projects at a time, but they will still appear under the respective project1
, etc. subdirectories. What I really want to end up with is the content of project
being in the root in each branch (including trunk).
Is there a way to do this?
I found the solution. It's not as simple as git svn clone
, but not too difficult. So, here's what I did (say, for project1
in the scenario from the question):
- Create an empty repo on the git server for
project1
- Clone the empty repo onto my local machine:
git clone git@git.server.com:group/project1.git
- Go into that empty repo working directory:
cd project1
- Init git svn repo:
git svn init --stdlayout --no-metadata https://svn.server.com/group
Now, here's where the magic comes. If at this point I run
git config --local --list
, I get the following (only relevant lines shown):svn-remote.svn.fetch=trunk:refs/remotes/trunk svn-remote.svn.branches=branches/*:refs/remotes/branches/* svn-remote.svn.tags=tags/*:refs/remotes/tags/*
All that I need to do now is
git config --local --edit
and addproject1
in the correct places:svn-remote.svn.fetch=trunk/project1:refs/remotes/trunk svn-remote.svn.branches=branches/*/project1:refs/remotes/branches/* svn-remote.svn.tags=tags/*/project1:refs/remotes/tags/*
Now you can
git svn fetch
Set branches and tags:
for branch in `git branch -r | grep "branches/" | sed 's/ branches\///'`; do git branch $branch refs/remotes/branches/$branch done for tag in `git branch -r | grep "tags/" | sed 's/ tags\///'`; do git tag -a -m"Converting SVN tags" $tag refs/remotes/tags/$tag done
And finally push it all to the remote:
git push --all origin git push --tags origin
Now if you clone your repo, you'll get the content of project1
in the root of your cloned repo - exactly what I was looking for.
这篇关于Svn只有一个子目录的Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!