是否可以将本地 Git 克隆视为从中克隆的存储库的完整备份?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4658451/
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
Can a local Git clone be considered a complete backup of the repo it was cloned from?
提问by Matt Hurne
Suppose I have cloned a Git repository to my local disk using:
假设我使用以下命令将 Git 存储库克隆到本地磁盘:
git clone [email protected]:someproject.git
Now suppose that git.example.com
is not being backed up, and it goes down in a blaze of glory. Does my clone contain everything necessary to rebuild the remote repo that was lost? The Ultimate Backupssection of Git Magicsuggests that the answer is "yes," but it isn't clear to me.
现在假设它git.example.com
没有得到备份,它在荣耀的光芒中消失了。我的克隆是否包含重建丢失的远程存储库所需的一切?Git Magic的Ultimate Backups部分表明答案是“是的”,但我不清楚。
Note that I'm not asking "is my local clone a sufficient backup of the master
branch?" I'm asking whether my local clone can be considered a completebackup of everythingthat was contained in the remote repo; all branches, all tags, everything. For example, what about remote branches that aren't tracked in the local repo?
请注意,我不是在问“我的本地克隆是否足以备份master
分支?” 我在问我的本地克隆是否可以被视为远程存储库中包含的所有内容的完整备份;所有分支,所有标签,一切。例如,本地存储库中未跟踪的远程分支呢?
To futher confuse the issue, the existence of git clone --mirror
suggests to me that my local clone should notbe considered a complete backup of the remote repo.
为了futher混淆问题,存在git clone --mirror
建议,我认为我的本地克隆应该不被视为远程回购的完整备份。
回答by James Gregory
A clone can be considered a full backup of all the data in your remote repository, but not necessarily the meta-data (that's where the --mirror
switch comes in). Your clone will contain all the commit, tree, blob, branch, and tag objects that are in any way referenced by the repository. That means your backup will contain all your source code, history, and associated branches or tags.
克隆可以被视为远程存储库中所有数据的完整备份,但不一定是元数据(那是--mirror
切换的地方)。您的克隆将包含存储库以任何方式引用的所有提交、树、blob、分支和标记对象。这意味着您的备份将包含您所有的源代码、历史记录和相关的分支或标签。
The difference with the --mirror
switch is that without it, the clone won't include things like remotes that have been created on the server. These are not important in a "I hope I haven't lost any source!" kind of way, but they may be for getting your server back up and running like it was.
与--mirror
交换机的不同之处在于,如果没有它,克隆将不包括在服务器上创建的遥控器之类的东西。这些在“我希望我没有丢失任何来源!”中并不重要。一种方式,但它们可能是为了让您的服务器像以前一样备份和运行。
If you're interested in creating a backup that can be restored onto the server like there was never any issue, then you should use --mirror
, but for most scenarios a simple clone is fine.
如果您有兴趣创建可以恢复到服务器上的备份,就像从来没有任何问题一样,那么您应该使用--mirror
,但对于大多数情况,简单的克隆就可以了。
回答by Abizern
Your local clone won't be a complete backup. It will be a backup of the state of thatrepository, but it won't have allthe refs of the source repository (so it won't know about the state of any remote branches).
您的本地克隆不会是完整的备份。它将是该存储库状态的备份,但它不会拥有源存储库的所有引用(因此它不会知道任何远程分支的状态)。
For a complete backup, you correctly found git clone --mirror
. This will not only have the branches for the original repository. It will also map all refs including remote branches.
对于完整备份,您正确地找到了git clone --mirror
. 这不仅会包含原始存储库的分支。它还将映射所有引用,包括远程分支。
回答by bobbogo
IMPORTANT
重要的
Without --mirror
, The clone will notbe a complete backup.
Any line of work not visible in git branch -r
will be elided from the clone.
没有--mirror
,克隆将不是完整的备份。任何不可见的工作行都git branch -r
将从克隆中删除。
Simple Demo
简单演示
Witness a simple repo.
见证一个简单的回购。
$ git init G
$ cd G
$ for f in 1 2 3 4; do date >1 && git add 1 && git commit -m $f; sleep 1.1; done
$ git log --oneline --graph --all --decorate
* 3c111bd (HEAD -> master) 4
* a08fea4 3
* d5c8d73 2
* 802856b 1
Add a branch:
添加一个分支:
$ git checkout d5c8d73
HEAD is now at d5c8d73... 2
$ git branch starts-at-2
$ git checkout starts-at-2
Switched to branch 'starts-at-2'
$ for f in 1 2 3 4; do date >1 && git add 1 && git commit -m 2-$f; sleep 1.1; done
$ git log --oneline --graph --all --decorate
* 6bb05bf (HEAD -> starts-at-2) 2-4
* fe1b635 2-3
* a9323fb 2-2
* 33502af 2-1
| * 3c111bd (master) 4
| * a08fea4 3
|/
* d5c8d73 2
* 802856b 1
Clone the repo.
克隆回购。
$ cd ..
$
$ git clone G G2
Cloning into 'G2'...
$ cd G2
$ git log --oneline --graph --all --decorate
* 6bb05bf (HEAD -> starts-at-2, origin/starts-at-2, origin/HEAD) 2-4
* fe1b635 2-3
* a9323fb 2-2
* 33502af 2-1
| * 3c111bd (origin/master) 4
| * a08fea4 3
|/
* d5c8d73 2
* 802856b 1
Fine. Clone again.
美好的。再次克隆。
$ cd ..
$ git clone G2 G3
$ cd G3
$ git log --oneline --graph --all --decorate
* 6bb05bf (HEAD -> starts-at-2, origin/starts-at-2, origin/HEAD) 2-4
* fe1b635 2-3
* a9323fb 2-2
* 33502af 2-1
* d5c8d73 2
* 802856b 1
Urk.
乌克。