从捆绑备份中恢复 git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9807367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:16:00  来源:igfitidea点击:

restoring git repository from bundle backup

gitbackuprestore

提问by user1283719

i created backups of my git repository like in How to backup a local Git repository?proposed with

我创建了我的 git 存储库的备份,如如何备份本地 Git 存储库?提出与

git bundle create /tmp/foo-all --all

I can see all refs are in there, including a remote ref created by git-svn. Now I can't figure out how to restore this bundle to a local repository again. I am quite quite sure i've done it already once. I tried git-clone but that gives me a just a repository with my backup bundle as remote repo.

我可以看到所有引用都在那里,包括由 git-svn 创建的远程引用。现在我不知道如何再次将这个包恢复到本地存储库。我很确定我已经做过一次了。我尝试了 git-clone 但这给了我一个存储库,我的备份包作为远程存储库。

I also tried

我也试过

git init
git bundle unbundle /tmp/foo --all 

but this just lists all references...

但这只是列出了所有参考资料......

Verifying the bundle gives:

验证捆绑提供:

$ git bundle verify $somewhere/foo.bundle 
The bundle contains 12 refs
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/master
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/heads/xxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx refs/remotes/git-svn
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HEAD
The bundle requires these 0 ref
$somewhere/foo.bundle is okay

回答by fbicknel

Short answer:

简短的回答:

$ git bundle verify $somewhere/foo.bundle
$ git clone $somewhere/foo.bundle
Cloning into 'foo'...
Receiving objects: 100% (10133/10133), 82.03 MiB | 74.25 MiB/s, done.
Resolving deltas: 100% (5436/5436), done.
$ cd foo
$ git status
...

Lazy Badger said this, but it's in the last paragraph. :)

懒獾是这么说的,不过是在最后一段。:)

回答by masterdany88

I newer version of git is enough to do:

我较新版本的 git 足以做:

git clone bundle.file

the whole commands:

整个命令:

mkdir ~/git
cd ~/git
git clone /path/to/bundle.file

It will restore completely Your's git bare repository content (which will compile as it is normal source). You don't need any other file. The bundle file is enough.

它将完全恢复您的 git 裸存储库内容(它将作为正常源进行编译)。您不需要任何其他文件。捆绑文件就足够了。

It is wise to always verify You bundle file before unbundle as follow:

明智的做法是在解包之前始终验证您的捆绑文件,如下所示:

git bundle verify /path/to/bundle.file 

回答by Lazy Badger

Bundle contain not files, but deltas, you need the basein order to recreate the file content. You have to clone first, unbundle later. Init instead of clone allowed only in case, where bundle requires 0 refs

Bundle 包含的不是文件,而是deltas,您需要基础才能重新创建文件内容。您必须先克隆,然后再解绑。仅在 bundle 需要 0 refs 的情况下才允许初始化而不是克隆

Don't ignore git bundle verifybefore unbundling

git bundle verify解绑前不要忽视

git-bundle(1) - Linux man page

git-bundle(1) - Linux 手册页

Used to check that a bundle file is valid and will apply cleanly to the current repository. This includes checks on the bundle format itself as well as checking that the prerequisite commits exist and are fully linked in the current repository. git bundle prints a list of missing commits, if any, and exits with a non-zero status.

用于检查捆绑文件是否有效并将干净地应用于当前存储库。这包括检查包格式本身以及检查先决条件提交是否存在并在当前存储库中完全链接。git bundle 打印丢失提交的列表(如果有),并以非零状态退出。

If you are creating the repository, then you can clone from the bundle as if it were a remote repository instead of creating an empty repository and then pulling or fetching objects from the bundle

如果您正在创建存储库,那么您可以从捆绑包中克隆,就像它是远程存储库一样,而不是创建一个空的存储库,然后从捆绑包中拉取或获取对象