How to git-svn clone the last n revisions from a Subversion repository?
Asked Answered
T

5

330

Problem

How do you create a shallow copy with git-svn from a Subversion repository, e.g. how do you pull only the last three revisions?

The git clone command can get the last n revisions from a Git repository if you use the option --depth, i.e. you get a shallow copy of the repository. Example:

git clone --depth 3 git://some/repo myshallowcopyrepo

Is there a similar option for git-svn?

My discoveries so far

So far I've only found the -rN option where N is the revision to pull. Example:

git svn clone -rN svn://some/repo

According to the documentation there is the possibility to use -r$REVNUMBER:HEAD. I tried the following to get the last 3 revisions which returned an error message.

$ git svn clone --prefix=svn/ -s -rHEAD~3:HEAD http://some/svn/repo .
revision argument: HEAD~3:HEAD not understood by git-svn

So I replaced HEAD~3 with the actual number of the third but last revision 534. That worked, but that requires me to first figure out the revision number of the third but last commit.

$ git svn clone --prefix=svn/ -s -r534:HEAD http://some/svn/repo .

Documentation

git-clone

git-svn

Tailwind answered 14/4, 2009 at 10:58 Comment(2)
Answering my own question: -s is for --stdlayout which presumes the svn recommended layout for tags, trunk, and branches. (but didn't work for me)Rochet
How hard would it be to implement --depth for git svn, since the support is already there. And it already has to find out the latest rev from the server?Uitlander
P
258

You've already discovered the simplest way to specify a shallow clone in Git-SVN, by specifying the SVN revision number that you want to start your clone at ( -r$REV:HEAD).

For example: git svn clone -s -r1450:HEAD some/svn/repo

Git's data structure is based on pointers in a directed acyclic graph (DAG), which makes it trivial to walk back n commits. But in SVN ( and therefore in Git-SVN) you will have to find the revision number yourself.

Periotic answered 14/4, 2009 at 19:39 Comment(5)
what if I'd like to continue cloning the earlier revision in the future, is it possible?Regan
@Zennichimaro: You can do that by adding another git-svn remote pointing at the same place and using git-svn fetch to get more of the tree. At that point you have to use git filter-branch to reparent the old (partial) tree onto the right branch.Omniumgatherum
Paul is there any way for me to get the latest revisions by performing Incremental Migration from SVN to Git (#29162146)Concinnate
SVN uses consecutive integers to identify revisions, making it even more trivial to walk back n commits ...Indiction
I think there is a space missing after -r. For e.g. git svn clone -r 1133:HEAD some/svn/repoHaze
A
96

I find myself using the following often to get a limited number of revisions out of our huge subversion tree (we're soon reaching svn revision 35000).

# checkout a specific revision
git svn clone -r N svn://some/repo/branch/some-branch
# enter it and get all commits since revision 'N'
cd some-branch
git svn rebase

And a good way to find out where a branch started is to do a svn log it and find the first one on the branch (the last one listed when doing):

svn log --stop-on-copy svn://some/repo/branch/some-branch

So far I have not really found the hassle worth it in tracking all branches. It takes too much time to clone and svn and git don't work together as good as I would like. I tend to create patch files and apply them on the git clone of another svn branch.

Abuttals answered 27/2, 2010 at 19:17 Comment(4)
+1 from me - helped me get round an error 128 issue I was having cloning an entire svn repoPolecat
the svn log command was exactly what I was looking for! thanksGoldman
Repos I work with have non-standard branching and layout, so I generally create a local Git repo for each SVN branch, and then cherry-pick/rebase between those. Commit takes an extra step (push, then dcommit from remote repo), but I think it's worth the tradeoff.Airs
Hadn't thought about that, might be quicker just cloning specific tags/branches as you say :)Unaesthetic
K
45

... 7 years later, in the desert, a tumbleweed blows by ...

I wasn't satisfied with the accepted answer so I created some scripts to do this for you available on Github. These should help anyone who wants to use git svn clone but doesn't want to clone the entire repository and doesn't want to hunt for a specific revision to clone from in the middle of the history (maybe you're cloning a bunch of repos). Here we can just clone the last N revisions:

Use git svn clone to clone the last 50 revisions

# -u    The SVN URL to clone
# -l    The limit of revisions
# -o    The output directory

./git-svn-cloneback.sh -u https://server/project/trunk -l 50 -o myproj --authors-file=svn-authors.txt

Find the previous N revision from an SVN repo

# -u    The SVN URL to clone
# -l    The limit of revisions

./svn-lookback.sh -u https://server/project/trunk -l 5     
Kelila answered 26/2, 2016 at 20:31 Comment(2)
Will give this a crack, our repo has about 170,000 revisions and it's taking waaaay too long to do a single project, and i have over 10 specific projects in the repo to do :| Considering just doing 3-4 years of history only.Unaesthetic
I forked Jonathan's idea, made some improvements, and removed the dependency on Python, available here: github.com/jstine35/git-svn-clonebackSultan
H
1

enter image description here

tried with tortoisegit tool from SVN repository option, its working for me.

Homosexuality answered 16/8, 2022 at 10:25 Comment(0)
S
0

I have had the error several times "revision argument: :HEAD not understood by git-svn"

it works by increasing the number of revision limits

for example 100 instead of 50

./git-svn-cloneback.sh -u https://server/project/trunk -l 100 -o myproj --authors-file=svn-authors.txt

Swec answered 21/6, 2022 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.