简体   繁体   English

Git可以将裸存储库克隆到另一个裸存储库

[英]Can Git clone a bare repository to another bare repository

I'm sure this can be done, i'm just not sure of the right way. 我确信这可以做到,我只是不确定正确的方法。

My scenario is to have a USB drive, a local hard drive and a network drive all connected to my PC at this point. 我的方案是将USB驱动器,本地硬盘驱动器和网络驱动器都连接到我的PC。 The local hard drive will contain the local active repo for my local work. 本地硬盘驱动器将包含本地工作的本地活动仓库。 The network drive (with a long UNC path!) would contain the main bare repo that acts as the upstream reference copy (2 or 3 collaborators in the office), while the USB drive acts as my mobile copy for sneakernetting to some external PCs (my other collaborators have their own drives, which may affect answers). 网络驱动器(具有长UNC路径!)将包含充当上游参考副本的主裸存储库(办公室中的2个或3个协作者),而USB驱动器充当我的移动拷贝到一些外部PC的sneakernet(我的其他合作者有自己的驱动器,这可能会影响答案)。 (this is on windows msysgit). (这是在windows msysgit上)。

It is the setting up of the USB drive that is the concern, and making sure I'm directing the workflow in the right direction (see using-git-on-usb-stick-for-travelling-code . 正是关注USB驱动器的设置,并确保我将工作流指向正确的方向(请参阅使用-git-on-usb-stick-for-travel-code

  • Should I be cloning my local repo, or cloning the network repo? 我应该克隆我的本地仓库,还是克隆网络仓库?
  • What are the special flags to make sure that the USB drive dismounts correctly? 有哪些特殊标志可确保USB驱动器正确卸下? (-nohardlinks?) (-nohardlinks?)
  • etc. 等等

You can create a bare-to-bare clone from the repo with the long UNC path to the USB stick with 您可以使用具有USB记忆棒的长UNC路径从repo创建一个裸到裸克隆

cd /e/src
git clone --bare //server/path/to/your/network/repo.git

but I doubt it buys you much to do it in one step. 但我怀疑它只需一步就可以为你买得多。

Given that you'll be working in your local active repo, I'd create a bare repo on the USB stick 鉴于您将在当地的活跃仓库中工作,我会在USB记忆棒上创建一个裸仓库

cd git init --bare /e/src/myproject.git

create a remote in your local active repo 在本地活动仓库中创建一个远程

git remote add usb file:///e/src/myproject.git

and then push to it as necessary. 然后根据需要推送它。

git push usb philip/cool-new-feature

The commands above assume your USB stick is E: and that your working directory is within your local active repo. 上面的命令假设您的USB记忆棒是E:并且您的工作目录在您的本地活动仓库中。

As I understand your question, you have at least two disjoint sets of collaborators, depending on whether your other collaborators share a common central repository of their own or are all working on isolated machines. 据我了解您的问题,您至少有两个不相交的协作者集合,具体取决于您的其他协作者是否共享他们自己的共同中央存储库,或者是否都在使用隔离的计算机。 This means the repository on your USB stick is the repository to which everyone (eventually) has access, so your teammates spend most of their time “on a plane” with respect to it. 这意味着USB记忆棒上的存储库是每个人(最终)都可以访问的存储库,因此您的团队成员将大部分时间花在“飞机上”上。

Suggestions for designing your development process: 设计开发过程的建议:

  1. Avoid the situation where you or someone else becomes The Designated Merger. 避免您或其他人成为指定合并的情况。 Instead, you want all members of the team to integrate as frequently as possible to keep potential for conflicting changes small and manageable. 相反,您希望团队中的所有成员尽可能频繁地集成,以保持冲突变更的可能性小且易于管理。
  2. Having disjoint collaborators increases the risk that someone will break a feature that someone else depends on, either through seemingly innocuous changes or incorrectly resolving merge conflicts. 拥有脱节的合作者会增加某人打破其他人依赖的功能的风险,无论是通过看似无害的更改还是错误地解决合并冲突。 You should have a quick, one-button method of determining whether any regressions or new bugs have snuck into your code. 您应该使用快速的一键式方法来确定是否有任何回归或新错误进入您的代码。
  3. Each group of collaborators, ie , those who have more frequent access to each other's repositories or a shared repository than to your USB stick, should practice continuous integration among themselves. 每组协作者, 那些更频繁访问彼此的存储库或共享存储库而不是USB存储库的人,应该在他们之间实现持续集成。 When new commits from the USB stick are available, integrating what they have with new code from the rest of the team should become top priority. 当有来自USB记忆棒的新提交时,将其所拥有的内容与来自团队其他成员的新代码集成应该成为首要任务。

One way you might do this is to have everyone keep a clean master and make changes only on other branches. 您可以这样做的一种方法是让每个人都保持干净的主人,并仅在其他分支上进行更改。 Physical possession of the USB stick is a natural integration token, so when a given collaborator has it, the sequence goes 物理拥有USB记忆棒是一种自然的集成令牌,因此当给定的协作者拥有它时,序列就会出现

git checkout master
git pull usb master     # should always be a fast-forward
git merge feature1
make test               # or whatever, and repeat until no breakage
git commit
git push usb master
git push shared master  # if appropriate
git merge feature2      # if necessary
...

I recommend creating a mirror clone of your main network repo: 我建议您创建主网络仓库的镜像克隆:

cd /path/to/usb/drive
git clone --mirror url://to/main/network/repo/project.git

A mirror clone is a bare repository with all the same branches, tags, etc. as the original repository. 镜像克隆是一个裸存储库,其中包含与原始存储库相同的分支,标记等。

Don't worry about passing --no-hardlinks because it's not possible to hardlink between file systems. 不要担心传递--no-hardlinks因为它不可能在文件系统之间进行硬链接。

Whenever you want to update your USB mirror, just mount it and run the following: 每当您想要更新USB镜像时,只需安装它并运行以下命令:

cd /path/to/usb/drive/project.git
git remote update -p

If you ever push into the USB drive mirror, the best way to get those commits to the main network repo is via your local hard drive repo: 如果你进入USB驱动器镜像,那么将这些提交到主网络仓库的最佳方法是通过本地硬盘驱动器回购:

# initial setup
cd /path/to/local/project
git remote add usb /path/to/usb/drive/project.git

# grab the commits from the usb drive
git remote update -p

# merge the usb drive commits into your local master branch
git merge usb/master

# push the result up to the main network repo
git push

You can clone from either. 你可以从任何一个克隆。 As soon as the usb drive finishes, you can remove it. 一旦USB驱动器完成,您可以将其删除。 You can double check integrity after with 你可以用后仔细检查完整性

git fsck --full

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

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