这将保存历史(
git log --follow
).
mkdir mainRepo
cd mainRepo
git init
git remote add repo1 (path to repo1.git)
git remote add repo2 (path to repo2.git)
git remote add repo3 (path to repo3.git)
git remote update
repo1_commit=$(
git commit-tree "$(
printf '040000 tree %s\t%s\0' "$(git rev-parse repo1/master^{tree})" repo1 \
| git mktree -z
)" -p repo1/master -m 'Move repo1 to subdirectory')
repo2_commit=$(
git commit-tree "$(
printf '040000 tree %s\t%s\0' "$(git rev-parse repo2/master^{tree})" repo2 \
| git mktree -z
)" -p repo2/master -m 'Move repo2 to subdirectory')
repo3_commit=$(
git commit-tree "$(
printf '040000 tree %s\t%s\0' "$(git rev-parse repo3/master^{tree})" repo3 \
| git mktree -z
)" -p repo3/master -m 'Move repo3 to subdirectory')
git reset --hard "$(
git commit-tree "$(
printf '040000 tree %s\t%s\0' \
"$(git rev-parse repo1/master^{tree})" repo1 \
"$(git rev-parse repo2/master^{tree})" repo2 \
"$(git rev-parse repo3/master^{tree})" repo3 \
| git mktree -z
)" \
-p "${repo1_commit}" -p "${repo2_commit}" -p "${repo3_commit}" \
-m 'Merge repo1, repo2, and repo3')"