转换为git时保留svn复制历史记录 [英] Retaining svn copy history when converting to git
问题描述
我正在尝试将SVN存储库转换为多个git存储库.到目前为止,我已经在SVN中的每个项目中使用了git svn clone svn_repo_project_path
.我注意到git似乎没有遵循svn复制操作,因此生成的历史记录比我期望的要简短得多.假设我的SVN回购看起来像这样:
I'm trying to convert an SVN repo over to multiple git repos. So far I have been using git svn clone svn_repo_project_path
for each project in SVN. I have noticed that git does not seem to follow svn copy operations so the resulting history is much briefer than I expect. Suppose my SVN repo looked like this:
root
- a
- b
- c
- 父母项目
- b
- c
- a
- b
- c
- parent-proj
- b
- c
项目
b
和c
最近被复制到parent-proj
下,这是重组工作的一部分,目的是最终从根目录下的旧位置删除它们.当我执行git svn clone http://svnhost/parent-proj
时,生成的git repo会丢失所有在移动之前源自/b
和/c
的历史记录.Projects
b
andc
were recently copied underparent-proj
as part of a restructuring effort with the intention of eventually deleting them from their old locations under root. When I dogit svn clone http://svnhost/parent-proj
the resulting git repo is missing all of the history that originated from/b
and/c
before the move.这是git-svn的限制吗,还是有某种方法可以使此历史记录显示在我的存储库中?从我的有限研究看来,使用
Is this a limitation of git-svn or is there some way to get this history to show up in my repo? From my limited research it seems that using the
filter-branch
command as described in Getting complete history of an SVN repo that's been renamed using git-svn may work although in my case there are multiple parents which probably complicates things. Could cloning the entire repo first and then splitting out new repos from it (using filter-branch?) be a better approach?推荐答案
如果您
git svn clone http://svnhost/parent-proj
,则不会获得b
或c
的预复制到父项目的历史记录.git svn
将您提供的基本路径解释为您有兴趣提取SVN提交的最浅点,使Git提交也一样.由于b
和c
下的历史提交不在此路径之内,因此git svn
不会镜像它们,因此您将没有该历史.You will not get pre-copy-to-parent-proj history for
b
orc
if yougit svn clone http://svnhost/parent-proj
.git svn
interprets your supplied base-path as the shallowest-point you are interested in ingesting the SVN commits for, making Git commits for the same. As the historical commits underb
andc
are outside of this path,git svn
won't mirror them, so you won't have that history.看看
git svn init --no-minimize-url
选项的文档:当跟踪多个目录(使用--stdlayout,--branches或--tags选项)时,git svn将尝试连接到Subversion存储库的根目录(或允许的最高级别).如果整个项目都在存储库中移动,则使用默认值可以更好地跟踪历史记录,但是可能会在存在读取访问限制的存储库上引起问题.传递--no-minimize-url将允许git svn照原样接受URL,而无需尝试连接到更高级别的目录.当仅跟踪一个URL/分支时,此选项默认为关闭(效果不佳).
When tracking multiple directories (using --stdlayout, --branches, or --tags options), git svn will attempt to connect to the root (or highest allowed level) of the Subversion repository. This default allows better tracking of history if entire projects are moved within a repository, but may cause issues on repositories where read access restrictions are in place. Passing --no-minimize-url will allow git svn to accept URLs as-is without attempting to connect to a higher level directory. This option is off by default when only one URL/branch is tracked (it would do little good).
由于您的
clone
命令未指定多个分支(可能是因为您具有复杂的多项目或非标准布局),因此git svn
只会克隆涉及该路径和向下路径的提交.注释中的Shadow Creeper使用-s
或--stdlayout
选项,这可以解释为什么为它们保留了一些历史记录.Since your
clone
command does not specify multiple branches (perhaps because you have a complex, multi-project or non-standard layout),git svn
just clones commits involving that path and downwards. Shadow Creeper in comments used the-s
or--stdlayout
option, which can explain why some history was preserved for them.如果这是一次转换(从SVN到Git的单向移动),则您可能应该克隆整个存储库,然后您有很好的选择在Git中移动内容,以查找所需的方式,包括建立历史分支和标签.如果运行
filter-branch
的动机是为了节省存储库空间,请确保这样做实际上可以为您节省一些东西,并且值得您花时间. Git的存储效率很高.If this is a one-off conversion (one-way move from SVN to Git), then you should probably clone the entire repository, then you have good options for moving things around in Git to look the way you want them to, including the establishment of historical branches and tags. If the motivation to run
filter-branch
is to save repository space, make sure that this is going to actually save you something, and that it is worth the bother. Git is very efficient with storage.最后的警告是对Git克隆中的历史搜索的期望.使用
git log -C --follow <file-path>
在文件上查找历史记录,Git通常会很好地查找并为您提供包含重命名和副本的历史记录.不要期望目录相同,例如parent-proj/b
. Git跟踪blob(文件),(blob的)树,提交和父提交,但不会以与SVN相同的方式处理目录或目录副本.One final word of caution on expections of history-searching in the Git clone. Look for history on a file using
git log -C --follow <file-path>
and Git will typically do a good job of locating and providing you with a history incorporating renames and copies. Don't expect the same for directories, e.g.parent-proj/b
. Git tracks blobs (files), trees (of blobs), commits and parent commits, but does not handle directories or directory-copies in the same way as SVN.这篇关于转换为git时保留svn复制历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!