简体   繁体   English

如何在不丢失任何提交的情况下将 git 存储库作为另一个 git 存储库的子目录导入?

[英]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 存储库TinyDroidsMiwok

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存储库必须有两个子目录: JustJavaMiwok 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.

相关问题 如何在不丢失本地存储库中的任何更改的情况下删除 GIT 中的提交消息并将其推送到远程存储库? - How to delete commit messages in GIT without losing any changes in local repository and push the same to remote repository? Git:如何在不丢失历史记录的情况下将存储库移动到另一个存储库? - Git: How to move repository in another repository without losing the history? 如何使用Git将存储库导入另一个存储库 - How to import a repository into another with Git git将子目录与另一个存储库合并 - git merge subdirectory with another repository 如何在另一个git存储库中提交git存储库 - How to commit a git repository inside another git repository Git:如何在不添加合并提交的情况下从另一个存储库中提取 - Git: How to pull from another repository without adding a merge commit 将git提交到远程存储库,而无需克隆任何本地存储库 - Commit git to remote repository without cloning any local repository (Git) 在不丢失当前更改的情况下将先前的提交推送到新的存储库 - (Git) Push a previous commit to a new repository without losing current changes git限制存储库子目录中的“添加”和“提交” - git restrict “add” and “commit” from subdirectory of repository 如何在不丢失分支的情况下将mercurial存储库转换为git存储库? - How to convert mercurial repository to git repository without losing branches?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM