apenwarrのgitサブツリーには、--squash
ほぼ必要なことを実行できるオプションがあります。
remote=libfoo
branch=master
prefix=helpers/libfoo
git fetch "$remote" &&
git subtree add --prefix="$prefix" --squash "$remote/$branch"
: Later, once there are changes to pick up.
git subtree pull --prefix="$prefix" --squash "$remote" "$branch"
gitサブツリーは、生成するコミットのコミットメッセージに追加情報を記録します。この追加情報により、マージされるサブツリーの実際の履歴を組み込むことなく、効果的にマージを実行できます。
「スーパー」リポジトリのサブツリーに変更を加えることは決してないことがわかっている場合(つまり、サブツリーのすべての変更は常に他のリポジトリから行われる)、gitサブツリーgit read-tree --prefix=
なしで行うことができ、その一部を繰り返すだけです。サブツリーマージメソッド(ただし、最初に両方のインデックスから現在のサブツリーをクリーンアップする必要があります)。
remote=libfoo
branch=master
prefix=helpers/libfoo/
: replace the local subtree with whatever the other repository has
git fetch "$remote" &&
git rm -r --ignore-unmatch "$prefix" &&
git read-tree --prefix="$prefix" "${remote}/${branch}" &&
git checkout -- "$prefix" &&
git commit -m "update $prefix from $remote $branch"