Git では、スタッシュを作成し、そのスタッシュをリモート リポジトリにプッシュし、別のコンピューターでスタッシュを取得して、そのスタッシュを適用することは可能ですか?
あるいは、私の選択肢は次のようになります:
- パッチを作成し、そのパッチを他のコンピュータにコピーするか、
- マイナー ブランチを作成し、未完了の作業をそのブランチにコミットしますか?
ベストアンサー1
注: 24 時間以上の git-fu を経て、この回答を書き直しました :) 私のシェル履歴では、全体が 3 つのワンライナーになっています。ただし、便宜上、要約しました。
こうすることで、ただ盲目的にコピー/貼り付けするのではなく、私がどのように作業を行ったかがわかるようになると思います。
手順は次のとおりです。
~/OLDREPO にスタッシュを含むソースがあると仮定します。スタッシュを含まない TEST クローンを作成します。
cd ~/OLDREPO
git clone . /tmp/TEST
すべてのスタッシュを一時ブランチとしてプッシュします。
git send-pack /tmp/TEST $(for sha in $(git rev-list -g stash); \
do echo $sha:refs/heads/stash_$sha; done)
受信側でループしてスタッシュに戻します。
cd /tmp/TEST/
for a in $(git rev-list --no-walk --glob='refs/heads/stash_*');
do
git checkout $a &&
git reset HEAD^ &&
git stash save "$(git log --format='%s' -1 HEAD@{1})"
done
必要に応じて一時的なブランチをクリーンアップします
git branch -D $(git branch|cut -c3-|grep ^stash_)
git stash list を実行すると、次のようになります。
stash@{0}: On (no branch): On testing: openmp import
stash@{1}: On (no branch): On testing: zfsrc
stash@{2}: On (no branch): WIP on sehe: 7006283 fixed wrong path to binary in debianized init script (reported as part of issue
stash@{3}: On (no branch): WIP on debian-collab: c5c8037 zfs_pool_alert should be installed by default
stash@{4}: On (no branch): WIP on xattrs: 3972694 removed braindead leftover -O0 flag
stash@{5}: On (no branch): WIP on testing: 3972694 removed braindead leftover -O0 flag
stash@{6}: On (no branch): WIP on testing: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{7}: On (no branch): WIP on xattrs: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{8}: On (no branch): WIP on testing: 28716d4 fixed implicit declaration of stat64
stash@{9}: On (no branch): WIP on emmanuel: bee6660 avoid unrelated changes
元のリポジトリでは、同じように見えました
stash@{0}: WIP on emmanuel: bee6660 avoid unrelated changes
stash@{1}: WIP on testing: 28716d4 fixed implicit declaration of stat64
stash@{2}: WIP on xattrs: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{3}: WIP on testing: db9f77e fuse_unmount_all could be starved for the mtx lock
stash@{4}: WIP on testing: 3972694 removed braindead leftover -O0 flag
stash@{5}: WIP on xattrs: 3972694 removed braindead leftover -O0 flag
stash@{6}: WIP on debian-collab: c5c8037 zfs_pool_alert should be installed by default
stash@{7}: WIP on sehe: 7006283 fixed wrong path to binary in debianized init script (reported as part of issue #57)
stash@{8}: On testing: zfsrc
stash@{9}: On testing: openmp import