在外部磁盘上备份整个 git 存储库的最佳方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4372832/
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-19 04:48:40  来源:igfitidea点击:

What is the best way to back up an entire git repository on external disk?

gitbackuprepository

提问by racl101

So I want to be able to back up a git repository that may have several branches onto an external hard drive and then be at a later time be able to copy it back onto my local machine and work with it as usual? I have tried simply copying the working directory folder containing the .git directory and it worked. However, I was wondering if this was the best way or if it had pitfalls later.

因此,我希望能够将可能有多个分支的 git 存储库备份到外部硬盘驱动器上,然后稍后能够将其复制回我的本地计算机并照常使用它?我试过简单地复制包含 .git 目录的工作目录文件夹,它工作正常。但是,我想知道这是最好的方法还是以后有陷阱。

回答by Thilo

Copying the entire working copy using regular file system copy commands works fine. You can also zip/tar the backup.

使用常规文件系统复制命令复制整个工作副本工作正常。您还可以压缩/ tar 备份。

If you are worried about disk space, you can also look at "git bundle", which could produce smaller files.

如果您担心磁盘空间,您还可以查看“ git bundle”,它可以生成更小的文件。

You can also get incremental backups by just starting a new repo on the external disk (git clone) and then pull the changes every time (git pull). There is not much difference between a backup and a working copy in a distributed system like git.

您还可以通过在外部磁盘 (git clone) 上启动一个新的存储库,然后每次拉取更改 (git pull) 来获取增量备份。在像 git 这样的分布式系统中,备份和工作副本之间没有太大区别。

回答by Cascabel

If you don't have any changes to back up in your work tree, you can use git clone --mirrorto create a bare clone with all refs (branches, tags, absolutely everything) copied verbatim. You can then use git push --mirrorto keep it up to date incrementally. This is what it's designed for.

如果您的工作树中没有任何要备份的更改,您可以使用git clone --mirror逐字复制所有引用(分支、标签、绝对所有)来创建一个裸克隆。然后,您可以使用git push --mirror它来逐步保持最新状态。这就是它的设计目的。

Copying the entire repo, including the work tree, works as well, but it's a bit of a pain to do incrementally, and obviously takes up more space.

复制整个 repo,包括工作树,也可以,但是增量式复制有点麻烦,而且显然会占用更多空间。

回答by cdhowie

That's about the only way to do it, short of cloning the repository onto the external disk. But either approach is approximately equivalent, except that copying your clone will preserve any repo-specific config settings.

这是唯一的方法,除了将存储库克隆到外部磁盘上。但是这两种方法大致等效,除了复制您的克隆将保留任何特定于存储库的配置设置。

回答by Lakshman Prasad

Summarizing,

总结一下,

  • You can just copy the damn directory, sure it works.
  • You can clone.
  • You can git bundleor git archive
  • 你可以复制该死的目录,确保它有效。
  • 你可以克隆。
  • 你可以git bundlegit archive

You can also,

你也可以,

which you can dump into a single file that you can import later from.

您可以将其转储到以后可以从中导入的单个文件中。

$ git fast-export --all | (cd /empty/repository && git fast-import)

回答by Jay

Copying the whole thing or using a sync tool is fine. The repo is fully contained and portable.

复制整个内容或使用同步工具都可以。回购是完全包含和便携的。

回答by RageZ

There is no pitfall here, git is a fully distributed SCM. Copying a working copy with the .gitdirectory is sufficient backup.

这里没有陷阱,git 是一个完全分布式的 SCM。使用.git目录复制工作副本就足够了。