简体   繁体   English

从包备份恢复 git 存储库

[英]restoring git repository from bundle backup

i created backups of my git repository like in How to backup a local Git repository?我创建了我的 git 存储库的备份,如如何备份本地 Git 存储库? proposed with建议与

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

I can see all refs are in there, including a remote ref created by git-svn.我可以看到所有引用都在那里,包括由 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-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

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. 懒惰獾说了这个,但它在最后一段。 :) :)

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). 它将完全恢复你的git裸存储库内容(它将编译为正常来源)。 You don't need any other file. 您不需要任何其他文件。 The bundle file is enough. 捆绑文件就足够了。

It is wise to always verify You bundle file before unbundle as follow: 在unbundle之前总是验证你捆绑文件是明智的,如下所示:

git bundle verify /path/to/bundle.file 

Bundle contain not files, but deltas , you need the base in order to recreate the file content. Bundle不包含文件,但包含增量 ,您需要基础才能重新创建文件内容。 You have to clone first, unbundle later. 你必须先克隆,然后再解开。 Init instead of clone allowed only in case, where bundle requires 0 refs 只有大小写允许初始化而不是克隆,其中bundle需要0 refs

Don't ignore git bundle verify before 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. 这包括检查bundle格式本身以及检查先决条件提交是否存在并在当前存储库中完全链接。 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 如果要创建存储库,则可以从包中克隆,就好像它是远程存储库而不是创建空存储库,然后从包中提取或提取对象

This should be the answer git clone -b main <bundleName.bundle>这应该是答案git clone -b main <bundleName.bundle>

git bundle unbundle /tmp/foo --all

but this just lists all references...但这只是列出了所有参考资料......

Actually, it now can do more than that:实际上,它现在可以做的远不止这些:

Git 2.34 (Q4 2021) adds progress display to " git bundle unbundle " ( man ) ". Git 2.34(2021 年第四季度)向“ git bundle unbundle( man ) “添加了进度显示。

In addition to git bundle verify mentioned in this answer , it will show you at least what is going on.除了这个答案中提到的git bundle verify ,它至少会告诉你发生了什么。

See commit d941cc4 , commit f46c46e , commit 7366096 (05 Sep 2021), and commit 0834257 (26 Aug 2021) by Ævar Arnfjörð Bjarmason ( avar ) .请参阅Ævar Arnfjörð Bjarmason ( avar ) 的commit d941cc4commit f46c46ecommit 7366096 (2021 年 9 月 5 日)和commit 0834257 (2021 年 8 月 26 日
(Merged by Junio C Hamano -- gitster -- in commit 67fc02b , 20 Sep 2021) (由Junio C gitster合并-- gitster -- in commit 67fc02b ,2021 年 9 月 20 日)

bundle : show progress on "unbundle" bundle : 显示“unbundle”的进度

Signed-off-by: Ævar Arnfjörð Bjarmason签字人:Ævar Arnfjörð Bjarmason

The "unbundle" command added in 2e0afaf ("Add git-bundle: move objects and references by archive", 2007-02-22, Git v1.5.1-rc1 -- merge ) did not show progress output, even though the underlying API learned how to show progress in be042af ("Teach progress eye-candy to fetch_refs_from_bundle() ", 2011-09-18, Git v1.7.8-rc0 -- merge ).2e0afaf 中添加的“ unbundle ”命令(“Add git-bundle: move objects and references by archive”,2007-02-22,Git v1.5.1-rc1 -- merge )没有显示进度输出,即使底层 API学习了如何在be042af 中显示进度(“Teach progress eye-candy to fetch_refs_from_bundle() ”,2011-09-18,Git fetch_refs_from_bundle() -rc0 -- merge )。

Now we'll show "Unbundling objects" using the new --progress-title option to git index-pack " ( man ) , to go with its existing "Receiving objects" and "Indexing objects" (which it shows when invoked with " --stdin ", and with a pack file, respectively).现在我们将使用git index-pack的新--progress-title选项来显示“分拆对象” man ,以配合其现有的“接收对象”和“索引对象”(它在使用“ --stdin ",并分别带有一个包文件)。

Unlike " git bundle create " ( man ) we don't handle " --quiet " here, nor " --all-progress " and " --all-progress-implied ".与“ git bundle createman )不同,我们不处理“ --quiet ”,也不处理“ --all-progress ”和“ --all-progress-implied ”。
Those are all specific to "create" (and "verify", in the case of " --quiet ").这些都是特定于“创建”(和“验证”,在“ --quiet ”的情况下)。

The structure of the existing documentation is a bit unclear, eg the documentation for the " --quiet " option added in 79862b6 (" bundle-create : progress output control", 2019-11-10, Git v2.25.0-rc0 -- merge listed in batch #2 ) only describes how it works for " create ", and not for " verify ".现有文档的结构有点不清楚,例如79862b6中添加的“ --quiet ”选项的文档(“ bundle-create :progress output control”,2019-11-10,Git v2.25.0-rc0-- 批处理 #2 中列出的合并)仅描述它如何用于“ create ”,而不是“ verify ”。
That and other issues in it should be fixed, but I'd like to avoid untangling that mess right now.应该修复其中的那个问题和其他问题,但我想避免现在就解开那个烂摊子。
Let's just support the standard " --no-progress " implicitly here, and leave cleaning up the general behavior of " git bundle " ( man ) for a later change.让我们在这里隐式地支持标准的“ --no-progress ”,并留下清理“ git bundleman的一般行为以供以后更改。

git bundle now includes in its man page : git bundle现在包含在其手册页中

 'git bundle' unbundle [--progress] <file> [<refname>...]

I tried git-clone but that gives me a just a repository with my backup bundle as remote repo.我尝试了 git-clone 但这给了我一个存储库,我的备份包作为远程存储库。

Bundle doesn't store original repository URL. Bundle 不存储原始存储库 URL。 You have to specify it manually:您必须手动指定它:

git clone foo.bundle
cd foo
git remote set-url origin url-to-original-repository

Now you can fetch from and push to original repository.现在您可以从原始存储库中获取并推送到原始存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM