3

谷歌一整天后,我将不得不请专家帮助我。

我克隆了一些我转换为 git 的公共 SVN 存储库。这个 repo 只有一个 master 分支,它从某个特定版本开始,比如 1.0。

我还有一个独立创建的 git repo,它以相同的 1.0 版本开始。我创建这个是因为我想破解一些公共项目。我刚刚下载了源代码,创建了空的 git repo,添加了 1.0 版,然后继续破解它。这个 repo 也只有 master 分支。

现在,我会撒谎创建第三个 git repo,其中版本 1.0 将是起点,它会有两个分支:'svn' 和 'mystuff'。我想保留两个分支的历史。

       1.0
      /   \
     /     \
br. svn    br. mystuff
     |       |
   v1.1      v1.1'
   v1.2      v1.2'
   v1.3      v1.3'
    .          .
    .          .

如果我有这个,我可以很容易地使用 svn2git 从 SVN repo 获得新的修订,并轻松地将它们与我的本地“mystuff”分支合并。我不需要推送到 SVN 回购,只需从中获取新的修订。

你能帮我再次使用 git 吗?

4

1 回答 1

2

一种骇人听闻的方法是使用git format-patch将一个 repo 的所有提交导出到一个目录,git checkout另一个的 repo1.0分支,创建一个新分支 ( git checkout -b new-branch),然后git am是你之前生成的补丁。

因此,让我们称public您为公共 SVN 存储库的克隆,以及local您通过下载源代码并入侵创建的 git 存储库。

cd local
mkdir ../patches

# -o tells the output directory for the patches
# the git log ... gives you the hash of the second commit of the repo (the first one
# changes are already present in your 'public' repo
git format-patch -o ../patches/ $(git log --pretty=format:%H | head -n-1 | tail -1)

cd ../public
git checkout -b mystuff 1.0
# Apply patches
git am ../patches/*
于 2012-11-17T16:50:00.930 回答