我刚刚将一个目录复制到另一个本地git仓库。事实证明,我复制的目录也是另一个git repo,所以现在我假设我称之为嵌套repo。
我想保留外部仓库,然后将内部仓库整合为外部仓库(根据需要修改远程原产地)。我担心的一个问题是因为内部仓库有几个分支。我想保留其中只有一个分支。
我对解决这个问题的最佳做法感到困惑。希望有人可以给我一些指示。谢谢!
您只能保留文件,而不是历史记录。
.git
文件夹和任何.git*
文件。在git shell
这样做:
/other/location/otherPrepo>git checkout the-branch-wanted
/other/location/otherPrepo>cp -R * -R /target/location/targetRepo/targetFolder/
/other/location/otherPrepo>rm -rf /target/location/targetRepo/targetFolder/.git*
/other/location/otherPrepo>cd /target/location/targetRepo/
/target/location/targetRepo/>git add targetFolder
/target/location/targetRepo/>git commit -m "added files from otherPrepo"
[编辑:]不要忘记签到...
您可以使用git subtree
从第二个存储库导入文件,同时保留其历史记录。
git status
)。如果您已尝试手动复制文件,请将其删除。 Git会为你复制它们。cd
到您的存储库的顶层。git subtree add --prefix=inner path/to/other/repo some-branch
。这将创建一个inner
子目录,并将其他repo的some-branch
的内容放入其中。git log
显示导入文件的历史记录。