如何 git-svn 从 Subversion 存储库克隆最后 n 个修订版?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/747075/
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 06:20:07  来源:igfitidea点击:

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

gitsvngit-svngit-clonesvn-checkout

提问by Lernkurve

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?

您如何使用 git-svn 从 Subversion 存储库创建浅拷贝,例如,您如何仅提取最后三个修订版?

The git clonecommand 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,该命令可以从 Git 存储库中获取最后 n 个修订版,即您获得存储库的浅拷贝。例子:

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 -rNoption where Nis the revision to pull. Example:

到目前为止,我只找到了要提取的修订版本的-rN选项N。例子:

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.

根据文档,可以使用-r$REVNUMBER:HEAD. 我尝试了以下方法来获取返回错误消息的最后 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~3with 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.

所以我用HEAD~3第三次但最后一次修订的实际编号 534替换。这有效,但这需要我首先找出第三次但最后一次提交的修订号。

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

Documentation

文档

git-clone

git-clone

git-svn

git-svn

采纳答案by Paul

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 ncommits. But in SVN ( and therefore in Git-SVN) you will have to find the revision number yourself.

Git 的数据结构基于有向无环图 (DAG) 中的指针,这使得回溯n提交变得微不足道。但是在 SVN 中(因此在 Git-SVN 中)你必须自己找到修订号。

回答by 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).

我发现自己经常使用以下内容从我们巨大的颠覆树中获得有限数量的修订(我们很快就会达到 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 logit 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. I tend to create patch files and apply them on the git clone of another svn branch.

到目前为止,我还没有真正发现跟踪所有分支的麻烦。克隆需要太多时间,svn 和 git 不能像我希望的那样协同工作。我倾向于创建补丁文件并将它们应用到另一个 svn 分支的 git clone 上。

回答by jonathan.cone

... 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. These should help anyone who wants to use git svn clonebut 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:

我对接受的答案不满意,因此我创建了一些脚本来为您执行此操作,可在 Github 上找到。这些应该可以帮助任何想要使用git svn clone但不想克隆整个存储库并且不想在历史中间寻找要克隆的特定修订版的人(也许您正在克隆一堆存储库)。在这里,我们可以克隆最近的 N 个修订版:

Use git svn cloneto 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