簡體   English   中英

如何在不丟失任何提交的情況下將 git 存儲庫作為另一個 git 存儲庫的子目錄導入?

[英]How to import a git repository as a subdirectory of another git repository without losing any commit?

我有兩個 GitHub 存儲庫TinyDroidsMiwok

TinyDroids有一個子目錄JustJava和一個README.md 這在日志中有大約 10 次提交。 Miwok在日志中有大約 12 次提交。

如何將整個Miwok存儲庫復制為TinyDroids存儲庫的子目錄?

生成的TinyDroids存儲庫必須有兩個子目錄: JustJavaMiwok 此外,它必須具有原始的 10 次提交 + 來自Miwok 12 次提交。

到目前為止我嘗試過的:

git clone https://github.com/username/TinyDroids.git
cd TinyDroids
git clone https://github.com/username/Miwok.git

如果我在此之后提交並推送,則整個Miwok子目錄將顯示為超過 10 個提交的單個提交。

我也試過:

git clone https://github.com/username/TinyDroids.git
cd TinyDroids
git pull --rebase https://github.com/username/Miwok.git

這在變基中產生了一些我不明白的問題。 此后的git log僅顯示Miwok的 12 次提交。

我建議創建一個分支並合並。 您可能還需要將Miwok目錄移動到所需的子目錄。 這是要做什么的粗略草圖:

$ 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

命令git mv . Miwok git mv . Miwok不能正常工作。 這個想法是將所有內容移動到Miwok子目錄。 您可能需要執行更多命令來手動執行此操作。

ps 由於這些是 Android Studio 項目,如果您希望它們成為單個項目中的模塊而不是兩個單獨的項目,則需要進行一些清理工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM