在满足以下要求的情况下,创建托管在 GitHub 上的 git 存储库的本地备份的最佳方法是什么?
本地备份应该是一个裸仓库。
备份应包括所有分支。
(增量)更新备份应该很容易。
基本上,我想要一个完美的镜像,可以轻松更新。因此,命令
git clone --mirror git://github.com/...
想到了,但据我所知,这不允许轻松更新(我必须删除并重新创建我的本地备份)。此外,git clone 的镜像选项似乎是最近才出现的,我正在使用的一些系统上没有它(这些系统运行的 git 版本稍旧)。
对于此类问题,您推荐的解决方案是什么?
最佳答案
我不确定它能否满足您的所有要求,但您可以查看 git bundle
git bundle
This command provides support for
git fetch
andgit pull
to operate by packaging objects and references in an archive at the originating machine, then importing those into another repository usinggit fetch
andgit pull
after moving the archive by some means
我喜欢该解决方案的一点是生成的单个文件,其中包含我想要的内容
git bundle
will only package references that are shown by git-show-ref: this includes heads, tags, and remote heads.
machineA$ git bundle create file.bundle master
备注:Kent Fredric在评论中提到了 git rev-list
的一个微妙之处:
--all
Pretend as if all the refs in
$GIT_DIR/refs/
are listed on the command line as<commit>
.
他补充说:
your current bundle will only bundle parents of the commit, you'd probably need to specify
--all
to get a complete bundle of everything (branches that are descendant of master).
查看区别:
$ git bundle create /tmp/foo master
$ git bundle create /tmp/foo-all --all
$ git bundle list-heads /tmp/foo
$ git bundle list-heads /tmp/foo-all
关于git - 备份 GitHub 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1251713/