我在一个相对较小的项目上使用 git,我发现压缩 .git 目录的内容可能是备份项目的好方法。但这有点奇怪,因为当我恢复时,我需要做的第一件事是 git reset --hard
。
用这种方式备份 git repo 有什么问题吗?另外,有没有更好的方法(例如,可移植的 git 格式或类似的格式?)?
最佳答案
另一种官方方式是使用 git bundle
这将创建一个支持 git fetch
和 git pull
的文件来更新你的第二个 repo。
对增量备份和恢复很有用。
但是,如果您需要备份所有内容(因为您没有第二个存储库,其中已经有一些旧内容),那么备份就有点复杂了,正如我在其他文章中提到的回答,在Kent Fredric之后的评论:
$ 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
文件夹中创建存档,如 commented by fantabolous )
警告:我不推荐 Pat Notz的 solution ,它正在克隆存储库。
备份许多文件总是比备份或更新...只是一个更棘手。
如果您查看 history of edits的 OP Yar answer ,您会看到 Yar 首先使用了 clone --mirror
,... 编辑:
Using this with Dropbox is a total mess.
You will have sync errors, and you CANNOT ROLL A DIRECTORY BACK IN DROPBOX.
Usegit bundle
if you want to back up to your dropbox.
亚的current solution使用 git bundle
。
我休息一下。
关于git - 如何备份本地 Git 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2129214/