如何更新 git clone --mirror?

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

How to update a git clone --mirror?

gitmirrorgit-clonegit-remotegit-fetch

提问by J. Bruni

I have created a git repository to mirror a live site (which is a non-bare git repository):

我创建了一个 git 存储库来镜像实时站点(这是一个非裸 git 存储库):

git clone --mirror ssh://[email protected]/path/to/repo

Now, to keep this mirror clone updated with all changes from its remote origin, which command or commands I must use?

现在,为了让这个镜像克隆更新来自其远程源的所有更改,我必须使用哪些命令?

I'd like to keep everything updated: commits, refs, hooks, branches, etc.

我想保持所有更新:提交、引用、钩子、分支等。

Thanks!

谢谢!

回答by ralphtheninja

This is the command that you need to execute on the mirror:

这是您需要在镜像上执行的命令:

git remote update

回答by J. Bruni

Regarding commits, refs, branches and "et cetera", Magnus answer just works (git remote update).

关于提交、引用、分支和“等等”,马格努斯的回答是有效的 ( git remote update)。

But unfortunately there is no way to clone/ mirror / updatethe hooks, as I wanted...

但不幸的是,没有办法clone/ 镜像 /update钩子,正如我想要的那样......

I have found this very interesting thread about cloning/mirroring the hooks:

我发现了这个关于克隆/镜像钩子的非常有趣的线程:

http://kerneltrap.org/mailarchive/git/2007/8/28/256180/thread

http://kerneltrap.org/mailarchive/git/2007/8/28/256180/thread

I learned:

我学会了:

  • The hooks are not considered part of the repository contents.

  • There is more data, like the .git/descriptionfolder, which does not get cloned, just as the hooks.

  • The default hooks that appear in the hooksdir comes from the TEMPLATE_DIR

  • There is this interesting templatefeature on git.

  • 钩子不被视为存储库内容的一部分。

  • 有更多的数据,比如.git/description文件夹,不会被克隆,就像钩子一样。

  • hooks目录中出现的默认钩子来自TEMPLATE_DIR

  • templategit 上有一个有趣的功能。

So, I may either ignore this "clone the hooks thing", or go for a rsyncstrategy, given the purposes of my mirror (backup + source for other clones, only).

因此,rsync考虑到我的镜像的目的(仅备份 + 其他克隆的源),我可能会忽略这个“克隆钩子的事情”,或者采取一种策略。

Well... I will just forget about hooks cloning, and stick to the git remote updateway.

嗯......我会忘记钩子克隆,并坚持下去git remote update

  • Sehe has just pointed out that not only "hooks" aren't managed by the clone/ updateprocess, but also stashes, rerere, etc... So, for a strict backup, rsyncor equivalent would really be the way to go. As this is not really necessary in my case (I can afford not having hooks, stashes, and so on), like I said, I will stick to the remote update.
  • Sehe刚指出,不仅是“钩子”不受管理clone/update流程,而且藏匿处,rerere,等等......所以,对于一个严格的备份,rsync或相当于真的是要走的路。因为在我的情况下这不是真正必要的(我可以负担不起没有钩子、藏匿处等),就像我说的那样,我会坚持remote update.

Thanks! Improved a bit of my own "git-fu"... :-)

谢谢!改进了我自己的“git-fu”... :-)

回答by sehe

See here: Git doesn't clone all branches on subsequent clones?

请参阅此处:Git 不会在后续克隆中克隆所有分支?

If you really want this by pulling branches instead of push --mirror, you can have a look here:

如果你真的想要通过拉分支而不是push --mirror,你可以看看这里:

"fetch --all" in a git bare repository doesn't synchronize local branches to the remote ones

git 裸存储库中的“fetch --all”不会将本地分支同步到远程分支

This answer provides detailed steps on how to achieve that relatively easily:

该答案提供了有关如何相对轻松地实现这一目标的详细步骤: