How to use git-svn to checkout only trunk and not branches and tags?
Solution 1
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:
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 clone
would look something like the following:
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
, branch
and tag
subfolders of the module1
folder, and clone them for you.
Solution 2
I have found git svn clone with --stdlayout didn't do quite the right thing for me.
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
Solution 3
I just wanted to add more information based on @me_and's answer.
the command given to clone just trunk is gonna work but in the git folder the structure created was:
refs
|--remotes
|--git-svn
which is equivalent of 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
The second structure looks more git-friendly and potentially could reduce the commands and shell scripts you have to write :)
P.S. the [--no-metadata] and [--author-file] arguments are optional.
- 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.
Related videos on Youtube
Comments
-
toy almost 4 years
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:
/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 clone
to checkout all the modules, but it's because it counts all the branches and tags.Is it possible to just clone the project only trunk so I can start committing locally?
-
Michael Wild about 11 yearsIs it important that you have the various modules in a single repo? Otherwise, just
git svn clone
the varioustrunks
of the modules into separate repos.
-
-
me_and about 11 years@toy: Yes. As per the first section, just run
git svn clone http://path.to.svn.repo/module1/trunk
. -
izikandrw about 8 yearswhat is $repo referring to? Can I put in the full http path to the repository instead?
-
Admin almost 8 yearsThis solution generates a git repository in the cloned project.
-
Kartal Tabak almost 8 years@maureliusfan4ever Yes, you can.
-
Gaurav about 5 yearsthis gives me a 404 error for the repo github.com/apache/hadoop.git/trunk
-
me_and about 5 years@gaurav
git svn clone https://github.com/apache/hadoop.git/trunk
works for me, although it seems odd to me you'd want to usegit svn
to clone the Subversion version of a Git repository, when you could just use Git to clone the Git repository in the first place. In any case, if you're continuing to have trouble, you're going to be better off asking a new question, as that'll get more visibility and provide more space to discuss. -
Víctor Martín about 2 yearsCan I execute git svn clone over the same folder of the project in svn or I need to launch it over other folder? I don't want to mantain 2 folders of the same project
-
me_and almost 2 years@VíctorMartín I don't understand what you're trying to achieve, but I suspect you'd be better asking that as a new question, where more people will see it and you'll have more space to provide context and details.