簡単な修正はありませんが、Ayushya Jaiswalによる非常によく書かれたガイドがここにあります(ファイルをあるリポジトリから別のリポジトリに移動し、gitの履歴を保持します)。アーカイブの目的でこの投稿で引用します。
tl; dr:基本的に、リポジトリを(安全に)リベースし、必要なファイルだけを抽出します。次に、リベースされたリポジトリから現在作業しているリポジトリにgit履歴をプルします。
始める前の注意事項:特定のファイルが必要な場合は、これにもhttps://stackoverflow.com/a/56334887/929999
が必要です。このステップで追加する場所を引用ガイドに以下の免責事項を追加します。
記事から引用したテキストは次のとおりです。
リポジトリAからファイルを移動する準備をします。
ステップ1:リポジトリAのコピーを作成します。次のステップでは、このコピーに大きな変更を加えますが、プッシュしないでください。
mkdir cloneA
cd cloneA
git clone --branch <branch> --origin origin --progress \
-v <git repository A url>
# eg. git clone --branch master --origin origin --progress \
# -v https://github.com/username/myproject.git
# (assuming myprojects is the repository you want to copy from)
ステップ2:そのディレクトリに移動します。
cd <git repository A directory>
# eg. cd myproject
# Folder Path is ~/cloneA/myproject
ステップ3:誤ってリモートで変更を加えないように(プッシュなど)、元のリポジトリへのリンクを削除します。
git remote rm origin
これは変更する手順です。代わりに、ここgit filter-branch --prune-empty ... $FILES
からの手順を実行して変更します。これにより、目的のファイルのみが推定されます。残りは同じである必要があります。
あなたの場合、それは次のようになります:
FILES='/a/b/c/d'
git filter-branch --prune-empty --index-filter "
git read-tree --empty
git reset \$GIT_COMMIT -- $FILES
" \
-- --all -- $FILES
ステップ4:履歴とファイルを調べて、にないものをすべて削除しますFOLDER_TO_KEEP
。FOLDER_TO_KEEP
結果は、リポジトリAのベースに吐き出されたコンテンツです。
git filter-branch --subdirectory-filter <directory> -- --all
# eg. git filter-branch --subdirectory-filter subfolder1/subfolder2/FOLDER_TO_KEEP -- --all
ステップ5:不要なデータをクリーンアップします。
git reset --hard
git gc --aggressive
git prune
git clean -fd
ステップ6:すべてのファイルとディレクトリをリポジトリBにプッシュするNEW_FOLDERに移動します。
mkdir <base directory>
#eg mkdir NEW_FOLDER
mv * <base directory>
#eg mv * NEW_FOLDER
または、GUIを使用してすべてのファイルとディレクトリをNEW_FOLDERにドラッグすることもできます。
ステップ7:変更を追加してコミットします。
git add .
git commit
ファイルを新しいリポジトリBにマージします。
ステップ1:リポジトリBをまだ持っていない場合は、そのコピーを作成します。
mkdir cloneB
cd cloneB
git clone <git repository B url>
# eg. git clone
https://github.com/username/newproject.git
ステップ2:そのディレクトリに移動します。
cd <git repository B directory>
# eg. cd newproject
# Folder Path is ~/cloneB/newproject
ステップ3:リポジトリBのブランチとしてリポジトリAへのリモート接続を作成します。
git remote add repo-A <git repository A directory>
# (repo-A can be anything - it's just a random name)
# eg. git remote add repo-A ~/cloneA/myproject
ステップ4:このブランチ(移動するディレクトリのみを含む)からリポジトリBにファイルと履歴をプルします。
git pull repo-A master --allow-unrelated-histories
# This merges master from repository A into repository B
手順5:リポジトリAへのリモート接続を削除します。
git remote rm repo-A
ステップ6:最後に、変更をプッシュします
git push
複製された両方のリポジトリを削除できます。
履歴に伴うファイルの変更は、リポジトリBでオンラインで利用できるようになりました。