如何使用 git-svn 只签出主干而不是分支和标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14585692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:22:41  来源:igfitidea点击:

How to use git-svn to checkout only trunk and not branches and tags?

gitsvngit-svn

提问by toy

I'm working on a Java legacy project which has 20 modules connected to each other. So, each module has it's own branch and tag. The structure is like this:

我正在开发一个 Java 遗留项目,该项目有 20 个相互连接的模块。所以,每个模块都有自己的分支和标签。结构是这样的:


/projects
   .svn
   - module1
       .svn
       -trunk
       -branch
       -tag
   - module2
       .svn
       -trunk
       -branch
       -tag

The projects folder is around 30 GB which is nearly impossible to use git-svn cloneto checkout all the modules, but it's because it counts all the branches and tags.

项目文件夹大约有 30 GB,几乎不可能用来git-svn clone检查所有模块,但这是因为它计算了所有分支和标签。

Is it possible to just clone the project only trunk so I can start committing locally?

是否可以只克隆项目主干以便我可以开始在本地提交?

回答by me_and

Edit: I misread the question and answered what I thought you were asking, not what you actually asked.

编辑:我误读了这个问题并回答了我认为你在问的问题,而不是你实际问的问题。

To clone just the trunk

只克隆主干

Cloning a single Subversion directory is easy, and it actually doesn't matter which directory you clone. Just don't specify any of the "layout" arguments, and give the path to the trunk directly:

克隆单个 Subversion 目录很容易,实际上克隆哪个目录并不重要。只是不要指定任何“布局”参数,并直接给出主干的路径:

git svn clone http://path.to.svn.repo/module1/trunk

To clone a specific module, including tags and branches and so forth

克隆特定模块,包括标签和分支等

A "normal" git svn clonewould look something like the following:

“正常”git svn clone将类似于以下内容:

git svn clone --stdlayout http://path.to.svn.repo/

What you want to use instead will be thus:

您想要使用的将是:

git svn clone --stdlayout http://path.to.svn.repo/module1/

That will find the trunk, branchand tagsubfolders of the module1folder, and clone them for you.

这将找到文件夹的trunk,branchtagmodule1文件夹,并为您克隆它们。

回答by Dewey Sasser

I have found git svn clone with --stdlayout didn't do quite the right thing for me.

我发现带有 --stdlayout 的 git svn clone 对我来说并不是很正确。

In the same situation this strategy worked well:

在同样的情况下,这种策略效果很好:

git svn init --trunk $repo/projects/module1/trunk --tags $repo/projects/module1/tag --branches $repo/projects/module1/branch
git svn fetch

回答by stucash

I just wanted to add more information based on @me_and's answer.

我只是想根据@me_and 的回答添加更多信息。

the command given to clone just trunk is gonna work but in the git folder the structure created was:

克隆只是主干的命令会起作用,但在 git 文件夹中创建的结构是:

refs
 |--remotes
    |--git-svn

which is equivalent of refs/remotes/git-svn.

这相当于refs/remotes/git-svn

if we do this instead:

如果我们这样做:

git svn clone https://domain/svn/repo/trunk --no-metadata --authors-file=authors.txt --trunk=https://domain/svn/repo/trunk

then the structure created is:

那么创建的结构是:

refs
 |--remotes
    |--origin
       |--trunk

which is equivalent to refs/remotes/origin/trunk

相当于refs/remotes/origin/trunk

The second structure looks more git-friendly and potentially could reduce the commands and shell scripts you have to write :)

第二种结构看起来更 git 友好,并且可能会减少您必须编写的命令和 shell 脚本:)

P.S.the [--no-metadata] and [--author-file] arguments are optional.

PS[--no-metadata] 和 [--author-file] 参数是可选的。

  • metadata option disables git to append svn information after commit message.
  • authors-file option allows you to map your svn contributors to git contributors so your svn historical revisions won't be messed up in git.
  • 元数据选项禁用 git 在提交消息后附加 svn 信息。
  • author-file 选项允许您将 svn 贡献者映射到 git 贡献者,这样您的 svn 历史修订就不会在 git 中搞砸。