是否有可能推git的藏匿到远程仓库?(Is it possible to push a git st

2019-07-22 00:14发布

在Git中,是否有可能创建一个存储,推到藏匿远程仓库,检索另一台计算机上藏匿,并应用藏匿?

或者是我的选择:

  • 创建一个补丁和补丁复制到另一台计算机,或
  • 创建一个小的分支,并承诺不完整的工作,那支?

Answer 1:

这是不可能得到它通过提取左右,镜子的Refspec是fetch = +refs/*:refs/* ,即使藏匿是refs/stash它不会发送。 一个明确的refs/stash:refs/stash也无济于事!

它只会混淆无论如何,因为这不会获取所有藏匿,只有最新的一个; 储物箱的列表是裁判的引用日志 refs/stashes



Answer 2:

注:我刚刚改写这个答案我带:)在24个多小时的git-FU在我的壳历史,整个事情,现在是三个一衬垫。 不过,我未冷凝他们为了您的方便。

这样一来,我希望你,而不是仅仅有盲目复制/粘贴的东西能看到我是如何做到的事情。


这里是一步一步来。

假定是在〜/ 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@{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


Answer 3:

我有点迟到了,但我相信,我发现的东西,对我的作品就这一点,它可能对你来说,如果你的情况相同或相似。

我的工作在自己的分支的特征。 该分支不合并到主推,直到其完成或我做了那提交我感觉很舒服展示给公众。 所以,当我想转移非暂存的变更到另一台计算机是我做​​的:

  • 做一个承诺,与像一个提交信息“ [non-commit] FOR TRANSFER ONLY ”,具有你想要转移的内容。
  • 登录到另一台计算机。
  • 然后做:

    git pull ssh+git://<username>@<domain>/path/to/project/ rb:lb

    如果你以不同的方式访问存储库中的URL可能会有所不同你。 这将拉从远程分支“RB”到当地分支机构“LB”从URL变化。 请注意,我有一个SSH服务器我自己的电脑上运行,并且我能够访问存储库的方式。

  • git reset HEAD^ (隐含--mixed

    这在“[非提交]”提交之前重置头指向的状态。

从git的复位(1):“ --mixed :重置索引而不是工作树(即更改的文件被保留,但不标记为提交)[...]”

所以,你将有你的改变到底文件,但没有提交由掌握,也不需要一个藏匿处。

然而,这将要求您git reset --hard HEAD^在你所做的“[非承诺]”,因为这是提交垃圾信息库。



Answer 4:

这是一个有点晚了,但是这个答案可能会帮助别人。 我想知道这是因为我希望能够推动正在进行中的特性/错误/无论从另一台计算机上的相同点的工作。

什么工作对我来说是犯我正在进行的代码(在我独自工作的一个分支)。 当我到了我的其他电脑,做一拉,然后撤消与承诺:

git reset --soft HEAD^

继续努力为你,你的所有正在进行的变化有,未提交的,不分级的和。

希望能帮助到你。



Answer 5:

似乎有一个非常巧妙的方法来解决这个问题。 你可以使用git diff > file.diff (然后提交该文件),然后使用还原变化git apply file.diff (从任何地方),以达到同样的效果。

这种解释在这里为好。



Answer 6:

我会跟虽然不知道第二个方法去,为什么你不能提交其掌握/独具特色的分支。 这是可以做到的樱桃采摘了。



Answer 7:

据我所知藏匿的整体思路是隐藏着什么地方地毯下不那么重要。 没有人应该知道你最喜欢的废话;-)唯一的“而是”是:但是,如果我的一对夫妇工作站发展? 然后scp是更好的方式。



Answer 8:

下列不与藏匿的工作,但在工作目录中提交的更改。 它创建了一个分支,autocommits目前所有的变化,并推送至远程:

commit_and_push_ ( ) {
    # This will:
    #  1. checkout a new branch stash-XXX
    #  2. commit the current changes in that branch
    #  3. push the branch to the remote
    local locbr=${1:-autostash-XXX}
    git checkout -b $locbr
    git add .
    git commit -a -m "Automatically created commit"
    git push origin $locbr
    echo "Autocommitted changes in branch $locbr ..."
}

使用这样的:

commit_and_push_ my-temp-branch
commit_and_push_


Answer 9:

只要使用Dropbox的像这家伙一样。 你不必这样担心推动储物箱,因为所有的代码会被备份。

http://blog.sapegin.me/all/github-vs-dropbox



文章来源: Is it possible to push a git stash to a remote repository?
标签: git git-stash