如何在克隆后没有链接的情况下使用捆绑包创建git存储库备份 [英] How to create a git repository backup with bundle where there is no linkage after cloning

查看:190
本文介绍了如何在克隆后没有链接的情况下使用捆绑包创建git存储库备份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 git bundle 来创建备份,其中在从备份克隆后没有与捆绑文件的链接?我想将我的存储库备份到一个包含所有历史记录的单个文件,并在以后恢复它们。

Is there a way to create a backup using git bundle where there is no linkage to the bundle file after cloning from the backup? I'd like to backup my repositories to a single file with all history and restore them, exactly, later.

目前,我正在使用以下方法:

At the moment, I'm creating a backup using the following methodology:

$ mkdir here                  
$ cd here                                                                       
$ git init                                                                      
Initialized empty Git repository in /tmp/here/.git/                             
$ touch stuff                                                                   
$ git add stuff                                                                 
$ git commit -m "This is a file"                                                
[master (root-commit) c867bcf] This is a file                                   
 1 file changed, 0 insertions(+), 0 deletions(-)                                
 create mode 100644 stuff                                                       
$ git bundle create myrepo.bundle --all                                         
Counting objects: 3, done.                                                      
Writing objects: 100% (3/3), 212 bytes | 212.00 KiB/s, done.                    
Total 3 (delta 0), reused 0 (delta 0)

好的,所以在这一点我们有一个简单的存储库捆绑。现在,当我们试图从软件包中复制这个存储库时:

Alright, so at this point we have a bundle with a simple repository. Now, when we try to copy this repository from the bundle:

$ cd ..
$ mkdir there                                                                   
$ cd there                                                                      
/tmp/there $ git clone ../here/myrepo.bundle .                                  
Cloning into '.'...                                                             
Receiving objects: 100% (3/3), done.                                            
/tmp/there $ git remote -v                                                      
origin→ /tmp/there/../here/myrepo.bundle (fetch)                                
origin→ /tmp/there/../here/myrepo.bundle (push)

这表明我们有一个指向原始包文件的链接,它我不想要。我也尝试创建镜像,但问题依然如此:

This shows that we have a link to the original bundle files, which I don't want. I also tried to create a mirror, but the problem remains the same:

$ cd ..                                                                         
$ mkdir there                                                                   
$ cd there                                                                      
$ git clone --mirror ../here/myrepo.bundle ./.git                               
Cloning into bare repository './.git'...                                        
Receiving objects: 100% (3/3), done.                                            
$ git config --bool core.bare false                                             
$ git reset --hard HEAD                                                         
HEAD is now at c867bcf This is a file                                           
/tmp/there $ git remote -v                                                      
origin→ /tmp/there/../here/myrepo.bundle (fetch)                                
origin→ /tmp/there/../here/myrepo.bundle (push) 

尽管我们可以直接复制整个存储库来备份,但我真的只想备份一个只有一个文件包含当前正在修订的文件。我一直在备份目录,并导致所有剩余文件的混乱。因此,我真的只想存档一个文件,这就是为什么我使用bundle的原因,并且我希望备份的恢复是干净的,因为根本没有任何关联到bundle文件。感谢您的帮助。

Although we could just copy the entire repository as is to back things up, I really only want to backup a single file that only contains the files currently under revision. I've been backing up the directories and it's been causing a mess with all of the leftover files. As such, I'd really only like to archive a single file, which is why I'm using bundle, and I'd like the recovery from the backup to be clean as in no linkages at all to the bundle file. Thanks for the help.

推荐答案

不是从包中克隆,而是使用通配符refspec创建一个新的存储库并获取。我已经在示例中添加了第二个分支特性和一个标记 v1.0 ,以使其更具说明性: p>

Instead of cloning from the bundle, create a new repository and fetch using a wildcard refspec. I have added a second branch feature and a tag v1.0 to the example to make this more illustrative:

$ mkdir there
$ git init .
$ git fetch --update-head-ok ../here/myrepo.bundle '*:*'
Receiving objects: 100% (5/5), done.
From ../here/myrepo.bundle
 * [new tag]         v1.0       -> v1.0
 * [new branch]      master     -> master
 * [new branch]      feature    -> feature
$ git checkout

*:* refspec会将所有远程引用读取到同名的本地引用中,如果它们不存在则创建它们。 - update-head-ok 参数是必需的,因为 git init 会创建一个 master

The *:* refspec will fetch all remote refs into equally named local refs, creating them if they don't exist. The --update-head-ok argument is needed since git init will create a master branch which is likely also present in the remote.

由于这是一个带有直接URL的提取,因此根本不需要遥控器。请注意,这对于任何类型的源repo URL都是一样的,而不仅仅是捆绑。

Since this is a fetch with a direct URL, no remotes are needed at all. Note that this would work equally for any kind of source repo URL, not just for bundles.

新旧版本库的参考文献的平等可以通过比较来检查这两个存储库中的 git show-ref 的输出,它们应该是相同的。

The equality of the refs of the old and new repository can be checked by comparing the output of git show-ref in both repositories, they should be identical.

这篇关于如何在克隆后没有链接的情况下使用捆绑包创建git存储库备份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆