本文翻译自: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, eg how do you pull only the last three revisions? 如何使用来自Subversion存储库的git-svn创建浅表副本,例如,如何仅提取最后三个修订版?
The git clone
command can get the last n revisions from a Git repository if you use the option --depth
, ie you get a shallow copy of the repository. 如果使用选项--depth
, git clone
命令可以从Git存储库获取最后n个修订版,即获得存储库的浅表副本。 Example: 例:
git clone --depth 3 git://some/repo myshallowcopyrepo
Is there a similar option for git-svn? git-svn有类似的选择吗?
My discoveries so far 到目前为止我的发现
So far I've only found the -rN
option where N
is the revision to pull. 到目前为止,我只找到-rN
选项,其中N
是要拉的修订版。 Example: 例:
git svn clone -rN svn://some/repo
According to the documentation there is the possibility to use -r$REVNUMBER:HEAD
. 根据文档,有可能使用-r$REVNUMBER:HEAD
。 I tried the following to get the last 3 revisions which returned an error message. 我尝试了以下内容来获取最后3个修订版,它们返回了一条错误消息。
$ 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. 所以我用第三个但最后一个修订版534的实际数字替换了HEAD~3
。这有效,但这要求我首先找出第三个但最后一次提交的修订号。
$ git svn clone --prefix=svn/ -s -r534:HEAD http://some/svn/repo .
Documentation 文档
参考:https://stackoom.com/question/38Lb/如何从Subversion存储库中git-svn克隆最后n个修订版
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). 我发现自己经常使用以下内容从我们巨大的颠覆树中获得有限数量的修订(我们很快就会达到svn修订版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
并找到分支上的第一个(执行时列出的最后一个):
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. 克隆和svn需要花费太多时间,并且git不能像我想的那样一起工作。 I tend to create patch files and apply them on the git clone of another svn branch. 我倾向于创建补丁文件并将其应用于另一个svn分支的git clone。
... 7 years later, in the desert, a tumbleweed blows by ... ... ... 7年后,在沙漠中,一个风滚草吹...
I wasn't satisfied with the accepted answer so I created some scripts to do this for you available on Github . 我对接受的答案不满意,所以我在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). 这些应该可以帮助任何想要使用git svn clone
但不想克隆整个存储库并且不想在历史中间寻找克隆的特定修订版本的人(也许你正在克隆一堆回购)。 Here we can just clone the last N revisions: 在这里,我们可以克隆最后N个修订:
Use git svn clone
to clone the last 50 revisions 使用git svn clone
克隆最近50个修订版
# -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 从SVN仓库中找到以前的N版本
# -u The SVN URL to clone
# -l The limit of revisions
./svn-lookback.sh -u https://server/project/trunk -l 5
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
). 您已经发现了在Git-SVN中指定浅层克隆的最简单方法,方法是在( -r$REV:HEAD
)指定要启动克隆的SVN修订版号。
For example: git svn clone -s -r1450:HEAD some/svn/repo
例如: 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. Git的数据结构基于有向非循环图(DAG)中的指针,这使得返回n
提交变得微不足道。 But in SVN ( and therefore in Git-SVN) you will have to find the revision number yourself. 但是在SVN(因此在Git-SVN中)你必须自己找到修订号。