ChatGPT解决这个技术问题 Extra ChatGPT

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

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

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)
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?

T
TamaMcGlinn

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.


what if I'd like to continue cloning the earlier revision in the future, is it possible?
@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.
Paul is there any way for me to get the latest revisions by performing Incremental Migration from SVN to Git (stackoverflow.com/questions/29161646/…)
SVN uses consecutive integers to identify revisions, making it even more trivial to walk back n commits ...
I think there is a space missing after -r. For e.g. git svn clone -r 1133:HEAD some/svn/repo
C
Christian

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.


+1 from me - helped me get round an error 128 issue I was having cloning an entire svn repo
the svn log command was exactly what I was looking for! thanks
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.
Hadn't thought about that, might be quicker just cloning specific tags/branches as you say :)
j
jonathan.cone

... 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     

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.
I forked Jonathan's idea, made some improvements, and removed the dependency on Python, available here: github.com/jstine35/git-svn-cloneback
9
936940

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