完全备份 git repo?

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

Fully backup a git repo?

gitbackup

提问by Daniel Upton

Is there a simple way to backup an entire git repo including all branches and tags?

有没有一种简单的方法来备份整个 git 存储库,包括所有分支和标签?

采纳答案by KingCrunch

Whats about just make a clone of it?

只是克隆它怎么样?

git clone --mirror other/repo.git

Every repository is a backup of its remote.

每个存储库都是其远程的备份。

回答by VonC

git bundle

I like that method, as it results in only onefile, easier to copy around.
See ProGit: little bundle of joy.
See also "How can I email someone a git repository?", where the command

我喜欢这种方法,因为它只生成一个文件,更容易复制。
请参阅ProGit:快乐的小捆绑
另请参阅“如何通过电子邮件向某人发送 git 存储库?”,其中的命令

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

is detailed:

详细说明:

git bundlewill only package references that are shown by git show-ref: this includes heads, tags, and remote heads.
It is very important that the basis used be held by the destination.
It is okay to err on the side of caution, causing the bundle file to contain objects already in the destination, as these are ignored when unpacking at the destination.

git bundle将只打包git show-ref 显示的引用:这包括头、标签和远程头。
使用的基础由目的地持有是非常重要的。
谨慎起见是可以的,这会导致捆绑文件包含目标中已有的对象,因为在目标解压缩时这些对象会被忽略。



For using that bundle, you can clone it, specifying a non-existent folder (outside of any git repo):

要使用该包,您可以克隆它,指定一个不存在的文件夹(在任何 git repo 之外):

git clone /tmp/foo-all newFolder

回答by fantabolous

Expanding on some other answers, this is what I do:

扩展一些其他答案,这就是我所做的:

Setup the repo: git clone --mirror user@server:/url-to-repo.git

设置回购: git clone --mirror user@server:/url-to-repo.git

Then when you want to refresh the backup: git remote updatefrom the clone location.

然后当你想刷新备份时:git remote update从克隆位置。

This backs up all branches and tags, including new ones that get added later, although it's worth noting that branches that get deleted do not get deleted from the clone (which for a backup may be a good thing).

这会备份所有分支和标签,包括稍后添加的新分支和标签,但值得注意的是,被删除的分支不会从克隆中删除(这对于备份可能是一件好事)。

This is atomic so doesn't have the problems that a simple copy would.

这是原子的,因此没有简单副本会出现的问题。

See http://www.garron.me/en/bits/backup-git-bare-repo.html

http://www.garron.me/en/bits/backup-git-bare-repo.html

回答by Kimmo Ahokas

Expanding on the great answers by KingCrunchand VonC

扩展KingCrunchVonC的精彩答案

I combined them both:

我将它们结合起来:

git clone --mirror [email protected]/reponame reponame.git
cd reponame.git
git bundle create reponame.bundle --all

After that you have a file called reponame.bundlethat can be easily copied around. You can then create a new normal git repository from that using git clone reponame.bundle reponame.

之后,您有一个名为的文件reponame.bundle,可以轻松复制。然后,您可以使用git clone reponame.bundle reponame.

Note that git bundleonly copies commits that lead to some reference (branch or tag) in the repository. So tangling commits are not stored to the bundle.

请注意,git bundle仅复制导致存储库中某些引用(分支或标签)的提交。所以纠结的提交不会存储到包中。

回答by Sunil Khiatani

use git bundle, or clone

使用 git bundle 或 clone

copying the git directory is not a good solution because it is not atomic. If you have a large repository that takes a long time to copy and someone pushes to your repository, it will affect your back up. Cloning or making a bundle will not have this problem.

复制 git 目录不是一个好的解决方案,因为它不是原子的。如果您有一个需要很长时间复制的大型存储库,并且有人推送到您的存储库,则会影响您的备份。克隆或制作捆绑包不会有这个问题。

回答by Oren Hizkiya

Everything is contained in the .gitdirectory. Just back that up along with your project as you would any file.

一切都包含在.git目录中。就像备份任何文件一样,将它与您的项目一起备份。

回答by Quanlong

You can backup the git repo with git-copyat minimum storage size.

您可以使用git-copy以最小存储大小备份 git repo 。

git copy /path/to/project /backup/project.repo.backup

Then you can restore your project with git clone

然后你可以恢复你的项目 git clone

git clone /backup/project.repo.backup project

回答by John

The correct answer IMO is git clone --mirror. This will fully backup your repo.

IMO 的正确答案是git clone --mirror。这将完全备份您的回购。

Git clone mirror will clone the entire repository, notes, heads, refs, etc. and is typically used to copy an entire repository to a new git server.This will pull down an all branches and everything, the entirerepository.

Git clone mirror 会克隆整个仓库、notes、heads、refs 等,通常用于将整个仓库复制到新的 git 服务器。这将拉下所有分支和所有内容,整个存储库。

git clone --mirror [email protected]/your-repo.git
  • Normally cloning a repo does not include all branches, only Master.

  • Copying the repo folder will only "copy" the branches that have been pulled in...so by default that is Master branch only or other branches you have checked-out previously.

  • The Git bundle command is also not what you want: "The bundle command will package up everything that would normally be pushed over the wire with a git push command into a binary file that you can email to someone or put on a flash drive, then unbundle into another repository." (From What's the difference between git clone --mirror and git clone --bare)

  • 通常克隆一个 repo 不包括所有分支,只包括 Master。

  • 复制 repo 文件夹只会“复制”已拉入的分支……因此默认情况下,只有主分支或您之前签出的其他分支。

  • Git bundle 命令也不是您想要的:“bundle 命令会将通常使用 git push 命令通过网络推送的所有内容打包成一个二进制文件,您可以通过电子邮件将其发送给某人或放在闪存驱动器上,然后解绑到另一个存储库。” (来自git clone --mirror 和 git clone --bare 之间的区别是什么

回答by vishal sahasrabuddhe

Here are two options:

这里有两个选项:

  1. You can directly take a tarof the git repo directory as it has the whole bare contents of the repo on server. There is a slight possibility that somebody may be working on repo while taking backup.

  2. The following command will give you the bare clone of repo (just like it is in server), then you can take a tar of the location where you have cloned without any issue.

    git clone --bare {your backup local repo} {new location where you want to clone}
    
  1. 您可以直接获取git repo 目录的tar,因为它在服务器上具有 repo 的全部裸内容。有人在备份时可能正在处理 repo 的可能性很小。

  2. 以下命令将为您提供 repo 的裸克隆(就像它在服务器中一样),然后您可以毫无问题地获取克隆位置的 tar。

    git clone --bare {your backup local repo} {new location where you want to clone}
    

回答by Mohammad

If it is on Github, Navigate to bitbucket and use "import repository" method to import your github repo as a private repo.

如果它在 Github 上,导航到 bitbucket 并使用“导入存储库”方法将您的 github 存储库作为私有存储库导入。

If it is in bitbucket, Do the otherway around.

如果它在 bitbucket 中,则相反。

It's a full backup but stays in the cloud which is my ideal method.

这是一个完整的备份,但保留在云中,这是我的理想方法。