如何组合两个Git存储库,一个是当前历史记录的另一个快照?

时间:2016-07-21 15:40:38

标签: git

我需要做this question的倒数。

因此,差不多一年前,我们通过将两个分支的当前状态复制到新的存储库中来分离我们的Git存储库。简单来说:

<== 2015 Dec              1 Jan                    2016 Jan ==>
Past history, till SVN    New Repo First Commit    All commits to present

我们很快将使用子树将此存储库中的每个项目转换为自己的Git存储库,但只要我们在中央存储库中缺少5年的提交历史记录,我就不想这样做。以下是我到目前为止尝试的步骤:

cd ProjectFull/
git reset --hard # Project was in a branch
git checkout master # Go to master before trying to rebase
git remote add ProjectSplit ../ProjectSplit # New repository is in another directory
git fetch ProjectSplit # Fetch new repository
git cherry-pick <initial commit hash> --strategy-option theirs
git pull --rebase -s recursive -X theirs origin master

我的想法是挑选新的repo的初始提交,然后重新关闭该提交,但是失败了。我上面列出的命令没有错误输出,但它们删除了旧存储库的所有历史记录。

这是我的Git rebase的截断日志:

$ git rebase origin dev
First, rewinding head to replay your work on top of it...
Applying: Merge branch 'dev' of <REPO> into dev
Using index info to reconstruct a base tree...
<stdin>:298480: trailing whitespace.

<stdin>:298553: trailing whitespace.

<stdin>:298559: trailing whitespace.

<stdin>:298565: trailing whitespace.

<stdin>:298571: trailing whitespace.

warning: squelched 1751272 whitespace errors
warning: 1751277 lines add whitespace errors.
Falling back to patching base and 3-way merge...

CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
CONFLICT (add/add): Merge conflict in <FILE>
Auto-merging <FILE>
<Same>

Failed to merge in the changes.
Patch failed at 0001 Merge branch 'dev' of <REPO> into dev
The copy of the patch that failed is found in:
   ProjectFull/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
这个回答中的

The script在旧回购补丁的中途失败了。

This answer仅适用于不同的存储库。

1 个答案:

答案 0 :(得分:1)

您的里程可能会有所不同,我可能误解了您的问题和意图,因此我会提出简短摘要的选项:

考虑拼接回购

Perl CPAN有git-stitch-repo,nice module可以将SyntaxError简化为git fast-export

应该线性化历史。

Subdir选项

有两个目录而不是一个。或multiple dirs

您正在遵循此程序。从你的问题中放弃最后的挑选,并将git fast-import repo作为目前的目录。

最不麻烦,只是将胶水堆放在一起。不尝试线性化历史。

Git子树合并

Merge subtree是一个Git命令,比子树和子模块更容易使用(并且管理程序更少)。

在查看单个文件的git日志时(合并后),您可能需要使用old

重新审视您需要它的原因

你确定它会有所帮助吗?如果你将旧的Git日志提供给ELK,索引搜索会更好地适合你的同事(和你自己)吗?有可能在Kibana设置一些仪表板吗?或者,如果您在具有旧回购的计算机上设置--follow,以便人们可以通过网络浏览它,它是否可以满足您的要求?

考虑git merge-repos

从未尝试过,所以不能推荐,但it's apparently for just such an occasion并且它是在git-stitch-repo年轻的时候写的。可能值得一试。

有些重写

还有an option with some history rewrite,带有git filter-branch。可能也可以用BFG完成。

相关问题