gpt4 book ai didi

git - 是否可以将 git stash 推送到远程存储库?

转载 作者:IT王子 更新时间:2023-10-29 01:16:30 26 4
gpt4 key购买 nike

在 git 中,是否可以创建存储,将存储推送到远程存储库,在另一台计算机上检索存储,然后应用存储?

或者我的选择是:

  • 创建补丁并将补丁复制到另一台计算机,或者
  • 创建一个次要分支并将未完成的工作提交给该分支?

最佳答案

注意:我刚刚用 24 小时以上的 git-fu 重写了这个答案:)在我的 shell 历史中,整个 shebang 现在是三个单行。但是,为了您的方便,我对它们进行了压缩。

通过这种方式,我希望您能够看到我是如何做的,而不是盲目地复制/粘贴东西。


这是一步一步的。

假设源代码在 ~/OLDREPO 中,包含存储。创建一个不包含任何存储的测试克隆:

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

关于git - 是否可以将 git stash 推送到远程存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1550378/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com