简体   繁体   English

如何使用push将一个git远程镜像到另一个远程镜像

[英]How to mirror one one git remote to another with push

The problem is a simple one. 问题很简单。 I've used git cvsimport to import a cvs repo into a remote branch in a local git repository. 我已经使用git cvsimport将cvs repo导入到本地git存储库中的远程分支中。 I then wish to sync this repository: branches, tags, and all, to a git repository in the cloud (github / gitorious). 然后,我希望将此存储库:branches,tags和all同步到云中的git存储库(github / gitorious)。 To do this I don't have the access to rsync or copy the repository directly, I have to use git push. 要做到这一点,我无法访问rsync或直接复制存储库,我必须使用git push。

How do I go about mirroring my local repository so others have access to the full _cvsimport_d history? 如何镜像我的本地存储库以便其他人可以访问完整的_cvsimport_d历史记录?

Concretely: 具体来说:
I import and track a repository using cvsimport: 我使用cvsimport导入和跟踪存储库:

git cvsimport -i -v -C cdt-make-core -d :pserver:anonymous@dev.eclipse.org:/cvsroot/tools -r cvs org.eclipse.cdt/all/org.eclipse.cdt.make.core

The above imports org.eclipse.cdt.make.core into the remote cvs in the git repo cdt-make-core. 以上导入org.eclipse.cdt.make.core进入git repo cdt-make-core中的远程cvs

I can then push the HEAD of the main CVS branch to github: 然后我可以将主CVS分支的HEAD推送到github:

git push github cvs/master:refs/heads/cvs/HEAD

(I specify the path on the remote explicitly so if it doesn't exist it's created.) (我明确指定了远程路径,所以如果它不存在则创建它。)

Is there any way to sync all the branches: cvs/* => cvs/* on the remote? 有没有办法同步所有分支:遥控器上的cvs / * => cvs / *?
Is there any way to sync all the tags? 有没有办法同步所有标签?

I think you're looking for the --mirror option to push: 我认为你正在寻找--mirror选项来推送:

git push --mirror github

This will push all refs (branches and tags) including non-fast-forward updates. 这将推送所有引用(分支和标记),包括非快进更新。 I use this for creating backups of my local repository. 我用它来创建本地存储库的备份。

The man page describes it like this: 手册页描述如下:

Instead of naming each ref to push, specifies that all refs under $GIT_DIR/refs/ (which includes but is not limited to refs/heads/ , refs/remotes/ , and refs/tags/ ) be mirrored to the remote repository. 而不是将每个引用命名为push,指定将$GIT_DIR/refs/ (包括但不限于refs/heads/refs/remotes/refs/tags/ )下的所有refs/tags/镜像到远程存储库。 Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. 新创建的本地引用将被推送到远程端,本地更新的引​​用将在远程端强制更新,并且已删除的引用将从远程端删除。 This is the default if the configuration option remote.<remote>.mirror is set. 如果设置了remote.<remote>.mirror配置选项,则这是缺省值。

[OT: I use CDT in my everyday work and I love it!] [OT:我在日常工作中使用CDT,我喜欢它!]

My findings are that if you use the 2nd reasonable solution below, you need to do the --mirror first, because it wipes out those cvs/ branches you're trying to push. 我的发现是,如果您使用下面的第二个合理解决方案,您需要首先执行--mirror ,因为它会清除您尝试推送的那些cv / branches。 So the complete formula is: 所以完整的公式是:

git push --mirror -v github
git push --force github cvs/master:refs/heads/cvs/HEAD
for x in `git branch -r | grep '^..cvs/[a-zA-Z0-9_-]*$' | sed -e 's/^..//'` ; do  
  git push -v github $x:refs/heads/$x
  git config branch.$x.remote github
  git config branch.$x.merge refs/heads/$x
done

Having experimented, I don't believe there's any built-in support for what I wish to do. 经过实验,我不相信对我想做的事情有任何内置的支持。

However there seem to be two reasonable solutions: 然而,似乎有两个合理的解决方案:

  • Don't specify -r to cvsimport. 不要将-r指定为cvsimport。
    The imported branches will then exist directly in the repository and --mirror can be used as Pat suggested. 然后,导入的分支将直接存在于存储库中,并且--mirror可以像Pat建议的那样使用。
  • Write a shell script to push the *cvs/** remotes one at a time (which is straightforward). 编写一个shell脚本,一次推送一个* cvs / **遥控器(这很简单)。
    Use --mirror so that tags are correctly synced 使用--mirror以便正确同步标记

I originally wanted to keep the cvsimport d branches separate for namespacing. 我最初想要将cvsimport d分支与namespacing分开。 However with the first option it makes sense to keep the cvsimport repository entirely separate (and only clone from it). 但是,对于第一个选项,保持cvsimport存储库完全独立(并且仅从中克隆)是有意义的。 I can then continue to track CVS with no risk of dirtying the tracking git repo. 然后,我可以继续跟踪CVS,而不会有跟踪git repo弄脏的风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM