无法使用git bundle导出本地git存储库

时间:2017-09-07 13:40:39

标签: git version-control

我一直在尝试使用git bundle命令导出我的本地git存储库。但似乎并非一切都是出口的。如何正确导出我的本地git存储库?我已经读过我不应该捆绑捆绑包但我应该克隆它。

PS C:\dev\repo\local-repo> git status
On branch dev
Your branch is up-to-date with 'origin/dev'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

        modified:   application/config/config.php
        modified:   application/controllers/Account.php
        modified:   application/controllers/Hook.php
        modified:   application/controllers/Test.php
        modified:   application/models/User.php
        modified:   application/views/backend/account/main.php
        modified:   application/views/backend/account/nav.php
        modified:   application/views/backend/referrals_table.php

Untracked files:
(use "git add <file>..." to include in what will be committed)

        application/models/Permission.php
        application/models/Referral.php
        application/models/Resellercredit.php
        application/models/Resellerpackage.php
        application/models/Usergroup.php
        application/views/backend/account/reseller_center.php

no changes added to commit (use "git add" and/or "git commit -a")

PS C:\dev\repo\local-repo> git branch
* dev
master

PS C:\dev\repo\local-repo> git stash list
stash@{0}: On dev: linux migration stash

PS C:\dev\repo\local-repo> git bundle create ..\migrate.git --all
Counting objects: 4249, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1546/1546), done.
Writing objects: 100% (4249/4249), 10.17 MiB | 0 bytes/s, done.
Total 4249 (delta 2709), reused 4186 (delta 2680)



PS C:\dev\repo> git clone migrate.git remote-repo
Cloning into 'remote-repo'...
Receiving objects: 100% (4249/4249), 10.17 MiB | 0 bytes/s, done.
Resolving deltas: 100% (2709/2709), done.

PS C:\dev\repo> cd .\remote-repo\
PS C:\dev\repo\remote-repo> git branch
* dev
PS C:\dev\repo\remote-repo> git stash
No local changes to save
PS C:\dev\repo\remote-repo> git stash list
PS C:\dev\repo\remote-repo>

我真的需要那个存储,因为它包含我未提交的文件。是否有其他替代方法可以导出我的整个本地存储库(包括未分级的更改)?我已经尝试将整个文件夹复制到另一台机器上(确切地说是另一台操作系统)但是当我运行git status时,更多的文件显示在&#34;未分级的更改&#34;。

1 个答案:

答案 0 :(得分:0)

创建捆绑包时,请添加引用refs/stash

git bundle create ..\migrate.git  refs/stash dev <other_refs>

在我的测试中,--all不起作用。所以我必须列出我需要的所有裁判,包括refs/stash

从捆绑包中进行克隆并检出分支(在您的情况下为dev)后,您可以运行git fetch ../migrate.git refs/stash;git stash apply FETCH_HEAD来检索隐藏的更改。然后,如果您想稍后再申请,可以运行git stash重新创建藏匿处。

如果您有多个存储条目,例如stash@{0}stash@{1} git stash list,则可以为每个存储条目创建一个标记。并将所有这些添加到捆绑包中。将它们应用于新克隆,然后重新创建存储条目。

git tag stash0 stash@{0}
git tag stash1 stash@{1}
git bundle create ../migrate.git stash0 stash1 dev <other_refs>
cd ..
git clone migrate.git -- sample
cd sample
git checkout dev
git stash apply stash0
git stash
git stash apply stash1
git stash
git tag -d stash0 stash1