不同存储库之间的 git 合并
我使用 git-svn 从一个大的 svn 存储库(git svn clone)创建了一个存储库。 我的 git 存储库中有几个本地提交,我不需要将它们推送到 svn,但我需要从中获取更新。
现在我意识到我不需要本地存储库中的整个 svn 历史记录,因为它使用了太多空间(一些 GB),并且我应该在克隆命令中使用 -r 选项来选择起点。
我会链接从新存储库开始,然后合并旧存储库中的所有本地提交,但我不确定是否有一种简单的方法可以做到这一点。
情况是这样的:
旧仓库的日志:
- local commit 10
- local commit 9 ...
- 本地提交 1
- svn 修订版 X
- svn 修订版 X-1 ...
- svn revision 1
新存储库只有一次提交,对应于 svn 存储库的修订版 X 的内容。
我尝试使用格式补丁并应用命令,但我不确定如何执行此操作。
有办法做我需要的事情吗?
感谢您的帮助
I created a repository with git-svn from a big svn repository (git svn clone).
I've several local commits in my git repository that I don't need to push to svn but I will need to get updates from it.
Now I realized that I don't need the entire svn history in my local repository, since it's using too much space (some Gb) and that I should have used the -r option in the clone command to select a starting point.
I'd linke to start over with a new repository and then merge all the local commits from the old repository, but I'm not sure there is a simple way to do this.
The situation is this:
log of the old repository:
- local commit 10
- local commit 9
... - local commit 1
- svn revision X
- svn revision X-1
... - svn revision 1
the new repository has just one commit, corresponding to the contend of the revision X of the svn repository.
I tried to use format-patch and apply commands but I'm not sure on how to do this.
Is there a way to do what I need?
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是,在您的新存储库中:
git remote add old
您的旧存储库;git fetch old
;完成后,
git Remote rm
旧存储库和git gc
。请参阅
git help rebase
了解--onto
选项:它非常非常有用。One method is, in your new repository:
git remote add old
your old repository;git fetch old
;git rebase --onto
.When done,
git remote rm
the old repo andgit gc
.See
git help rebase
for the--onto
option: it is very, very useful.您可以首先从 SVN 存储库中检出修订版 X,并删除所有与 SVN 相关的文件夹。然后 git init && git 添加 . && git commit -m“从 SVN 导入修订版 X”。现在您已经有了一个包含 SVN 修订版 X 快照的 Git 存储库。
之后您可以使用 git format-patch 从旧 Git 存储库创建补丁。
git format-patch x..
其中x
是相当于 SVN 修订版 X 的提交。它将生成补丁文件。在旧的 Git 存储库中执行它。随后,在新存储库中,您可以 git am all_those_patches.* 来将它们应用到新存储库中。
比照。
man git-am
,man git-format-patch
。You could begin with checking out the revision X from the SVN repository and getting rid of all SVN-related folders. Then
git init && git add . && git commit -m "Importing revision X from SVN"
. Now you've got a Git repository with a snapshot of SVN's revision X.Afterwards you could use
git format-patch
to create patches from your old Git repository.git format-patch x..
wherex
is the commit equivalent to revision X from SVN. It will generate patch files. Execute it in the old Git repository.Subsequently, in the new repository you can
git am all_those_patches.*
to get them applied in the new repository.Cf.
man git-am
,man git-format-patch
.