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

标签 git git-stash

在 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/

相关文章:

git - 所以更改了 Git 的默认编辑器,现在我如何从 Git bash 调用它?

git - 防止对后续 pull 请求重复提交

git - 我怎样才能避免像这样奇怪的 git 差异?

如果之前没有在 Azure 上运行 ssh-add -K,Git pull 将无法工作

git - 发出 git log 命令时 PowerShell 挂起

git - 获取存储的创建日期

git - 如何忽略 'git pull' 上关于我的本地更改将被 merge 覆盖的错误?

git - 将 Git 存储备份到 GitHub

git - 我怎样才能一次保存我所有的 Git 存储差异?

git - IntelliJ 的 Shelve 和 Git stash 有什么区别?