2

上下文:我正在将 Git 用于我正在开发的应用程序。我的应用程序使用了一个开源库,我根据自己的需要对其进行了修补。这个开源库在 SVN 中。

问题:我正在寻找一种在我的 Git 存储库中导入和维护这个 3rd 方组件的方法。我不需要将补丁推送到上游。

开源库的 SVN 存储库非常标准。

trunk/
tags/
 - v1/
 - v2/
branches/

我的 Git 工作副本中的目录结构非常简单。

my_app/
lib/

我应该如何从标签 v1 中导入 lib 的源代码lib/

当其开发团队在其 SVN 存储库中创建标签 v2 时,我如何合并或重新构建库的新版本?

为了展示一个具体的例子,我创建了一个 bash 脚本:

# Create the open source library's SVN repo and its first tag.
svnadmin create lib_svn_repo/
svn checkout "file:///${PWD}/lib_svn_repo/" lib_working_copy
( cd lib_working_copy ; mkdir -p trunk tags branches ; svn add * ; svn commit -m 'Initialize SVN repo' ; cd trunk ; echo "print 'Hello v1'" >source.py ; svn add * ; svn commit -m 'Development for v1' ; cd .. ; svn up ; svn cp trunk/ tags/v1 ; svn commit -m 'Tag v1' ; sed --in-place 's/v1/v2/' trunk/* ; svn commit -m 'Development for v2' )

# Initialize my own project's git repository.
mkdir my_app
( cd $_ ; git init ; mkdir -p src lib ; touch src/.gitignore ; git add * ; git commit -m 'Initialize my app' )

# How to import the lib source code from tag v1 in the lib subdirectory???
# Expected: lib/ contains a source.py that displays "Hello v1".

# Commit local changes in my git repo.
( cd my_app/ ; echo "print 'My local modification'" >>lib/source.py ; git add * ; git commit -m 'Added local modification to the library' )

# Library dev team creates a tag v2.
( cd lib_working_copy ; svn up ; svn cp trunk/ tags/v2 ; svn commit -m 'Tag v2' )

# How to merge or rebase lib/ on tag v2???
# Expected: lib/ contains a source.py file that displays both "Hello v2" and "My local modification".
4

1 回答 1

1

然后(因为您不需要历史记录)我建议您导出 svn 存储库并将其作为文件导入到您的 git 存储库中,这是最简单的。

然后监视您关心的外部 svn 存储库中标签的更改,并将基于外部 svn 存储库的差异作为补丁应用到您的 git 存储库。

于 2013-07-27T18:59:49.933 回答