[英]How to import a git repository as a subdirectory of another git repository without losing any commit?
I have two GitHub repositories TinyDroids
and Miwok
我有两个 GitHub 存储库TinyDroids
和Miwok
TinyDroids
has a subdirectory JustJava
and a README.md
. TinyDroids
有一个子目录JustJava
和一个README.md
。 This has about 10 commits in the log.这在日志中有大约 10 次提交。 Miwok
has about 12 commits in the log. Miwok
在日志中有大约 12 次提交。
How can I copy the entire Miwok
repository as a subdirectory of TinyDroids
repository?如何将整个Miwok
存储库复制为TinyDroids
存储库的子目录?
The resultant TinyDroids
repository must have two subdirectores: JustJava
and Miwok
.生成的TinyDroids
存储库必须有两个子目录: JustJava
和Miwok
。 Also, it must have its original 10 commits + 12 commits from Miwok
.此外,它必须具有原始的 10 次提交 + 来自Miwok
12 次提交。
What I tried so far:到目前为止我尝试过的:
git clone https://github.com/username/TinyDroids.git
cd TinyDroids
git clone https://github.com/username/Miwok.git
If I commit and push after this, the entire Miwok
subirectory is shown as a single commit over the 10 commits.如果我在此之后提交并推送,则整个Miwok
子目录将显示为超过 10 个提交的单个提交。
I also tried:我也试过:
git clone https://github.com/username/TinyDroids.git
cd TinyDroids
git pull --rebase https://github.com/username/Miwok.git
This gives some issues in rebasing that I do not understand.这在变基中产生了一些我不明白的问题。 git log
after this only show the 12 commits of Miwok
.此后的git log
仅显示Miwok
的 12 次提交。
I suggest creating a branch and merging.我建议创建一个分支并合并。 You also might need to move the Miwok
directory to the desired subdirectory.您可能还需要将Miwok
目录移动到所需的子目录。 This is a rough sketch of what to do:这是要做什么的粗略草图:
$ git clone https://github.com/username/TinyDroids.git
$ cd TinyDroids
# Create an orphan branch to pull the Miwok repo to
$ git checkout --orphan miwok
$ git pull https://github.com/username/Miwok.git
# Move the Miwok repo into a subdir
$ mkdir Miwok
$ git mv . Miwok
$ git commit -m "Move Miwok repo to Miwok subdir"
# Merge Miwok into TinyDroids
$ git checkout master
$ git merge miwok
The command git mv . Miwok
命令git mv . Miwok
git mv . Miwok
won't quite work right. git mv . Miwok
不能正常工作。 The idea is to move everything to the Miwok
subdirectory.这个想法是将所有内容移动到Miwok
子目录。 You might need to do a few more commands to do this more manually.您可能需要执行更多命令来手动执行此操作。
ps Since these are Android Studio projects, you will need to do some housecleaning if you want them to be modules in a single project instead of two separate projects. ps 由于这些是 Android Studio 项目,如果您希望它们成为单个项目中的模块而不是两个单独的项目,则需要进行一些清理工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.