git - 在保留历史记录的同时在 Git 存储库之间移动文件

标签 git merge git-filter-branch

<分区>

Possible Duplicate:
How to move files from one git repo to another (not a clone), preserving history

我按照步骤在

How to move files from one git repo to another (not a clone), preserving history

我确实把文件移了过来,但它带来了整个 repo 协议(protocol)的历史!

有没有办法做同样的事情,但只带来相关文件的历史而不是存储库的整个历史?

编辑:

为了更明确地说明我正在尝试做什么,假设存储库中有 10 个文件,每个文件都有 1 个与之关联的提交(因此日志中总共有 10 个提交)。

我有一个新的存储库,我想将其中的一些文件传输到其中,比如说其中的 2 个。我想将这些文件与这些文件的历史一起带过来,所以我希望在新 repo 的日志中有 2 次来自原始 repo 的提交。上面使用的方法带来了所有 10 次提交,即使只有 2 个文件过来了。

最佳答案

你试过了吗Subtree Merging

Subtree Merging The idea of the subtree merge is that you have two projects, and one of the projects maps to a subdirectory of the other one and vice versa. When you specify a subtree merge, Git is often smart enough to figure out that one is a subtree of the other and merge appropriately.

We’ll go through an example of adding a separate project into an existing project and then merging the code of the second into a subdirectory of the first.

关于git - 在保留历史记录的同时在 Git 存储库之间移动文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8453104/

相关文章:

python - 执行合并,同时存储所有其他数据并保留原始数据的顺序

recursion - 归并排序,递归部分

git - 拆分巨大的 git 仓库

python - 如何在 Python 中正确合并重叠的日期时间范围

git - 如何使用 filter-branch 从 git 中删除文件,这样我仍然不能 git grep 内容?

git - 如何在 git 中启用 shell 选项?

git - 使用 subgit 迁移没有分支、标签和主干的非标准布局 subversion 存储库

git - .gitignore 不会停止在文件中跟踪更改

git - 为什么我会与 git rebase -p -i 发生冲突?

git - 了解 Mercurial、Bazaar 等的内部结构?