Gitリポジトリの履歴をサブディレクトリに再生するには?

Gitリポジトリの履歴をサブディレクトリに再生するには?

aye2つのリポジトリがあり、この方法で新しいサブディレクトリ(複数レベルの深さ)から「再生」の線形記録をbee削除したいとします。beebee/masterayeファイルとコミットメッセージだけが必要で、コミットIDは気にしません。する合理的な歴史が欲しいからgit subtree add --prefix=subdirectoryそしてgit read-tree --prefix=subdirectory/私が探しているものではありません。

両方のリポジトリは非公開であるため、他のリポジトリに対して履歴を書き換えるリスクはありません。しかし、bee するサブモジュールがありますcee

ベストアンサー1

まず、履歴を書き換えてbeeすべてのファイルをサブディレクトリに移動する:

cd /path/to/bee
git filter-branch --force --prune-empty --tree-filter '
dir="my fancy/target directory"
if [ ! -e "$dir" ]
then
    mkdir --parents "${dir}"
    git ls-tree --name-only "$GIT_COMMIT" | xargs -I files mv files "$dir"
fi'

git log --statこれで表示する必要がありますmy fancy/target directoryaye記録を簡単にマージ:

cd /path/to/aye
git remote add -f bee /path/to/bee
git checkout -b bee-master bee/master
git rebase master
git checkout master
git rebase bee-master

次の場所でサブモジュールを再作成しますaye

git submodule add git://my-submodule 'my fancy/target directory/my-submodule'

最後に整理できますaye

git rm 'my fancy/target directory/.gitmodules'
git branch --delete --force bee-master
git remote remove bee

リポジトリの絶対パスを変更する必要があるかもしれません.gitignore

おすすめ記事