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

发布于 2024-11-16 05:53:28 字数 537 浏览 1 评论 0原文

我确信这是可以做到的,我只是不确定正确的方法。

我的场景是,此时将 USB 驱动器、本地硬盘驱动器和网络驱动器全部连接到我的 PC。本地硬盘将包含我本地工作的本地活动存储库。网络驱动器(具有很长的 UNC 路径!)将包含主要的裸存储库,充当上游参考副本(办公室中的 2 或 3 个协作者),而 USB 驱动器充当我的移动副本,用于连接到某些外部 PC(我的其他合作者有自己的驱动器,这可能会影响答案)。 (这是在 Windows msysgit 上)。

值得关注的是 USB 驱动器的设置,并确保我将工作流程引导到正确的方向(请参阅 using-git-on-usb-stick-for-travelling-code

  • 我应该克隆本地存储库还是克隆网络存储库?
  • 什么是确保 USB 驱动器正确卸载的特殊标志(-nohardlinks?)
  • 等。

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. 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). (this is on 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 .

  • 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? (-nohardlinks?)
  • etc.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

土豪 2024-11-23 05:53:28

您可以从存储库创建一个裸到裸的克隆,并使用到 USB 记忆棒的长 UNC 路径,

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

但我怀疑这对您一步完成此操作是否有帮助。

鉴于您将在本地活动存储库中工作,我将在 USB 记忆棒上创建一个裸存储库,

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

在本地活动存储库中创建一个遥控器

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

,然后根据需要推送到它。

git push usb philip/cool-new-feature

上面的命令假设您的 USB 记忆棒是 E: 并且您的工作目录位于本地活动存储库中。

据我了解您的问题,您至少有两组不相交的协作者,具体取决于您的其他协作者是否共享自己的公共中央存储库,或者都在独立的计算机上工作。这意味着您的 USB 记忆棒上的存储库是每个人(最终)都可以访问的存储库,因此您的队友将大部分时间都花在“飞机上”上。

设计开发流程的建议:

  1. 避免出现您或其他人成为指定合并者的情况。相反,您希望团队的所有成员尽可能频繁地进行集成,以使冲突变更的可能性保持在较小且易于管理的范围内。
  2. 不相交的协作者会增加有人破坏其他人所依赖的功能的风险,无论是通过看似无害的更改还是错误地解决合并冲突。您应该有一种快速、一键式的方法来确定代码中是否存在任何回归或新错误。
  3. 每组协作者(即那些更频繁地访问彼此的存储库或共享存储库而不是 USB 记忆棒的人)应该在彼此之间进行持续集成。当 USB 记忆棒中的新提交可用时,将他们拥有的内容与团队其他成员的新代码集成应该成为首要任务。

实现此目的的一种方法是让每个人都保持一个干净的 master 并仅在其他分支上进行更改。物理拥有 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
...

You can create a bare-to-bare clone from the repo with the long UNC path to the USB stick with

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

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.

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.

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, i.e., 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. 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.

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

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
...
痕至 2024-11-23 05:53:28

我建议创建主网络存储库的镜像克隆:

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

镜像克隆是一个裸存储库,具有与原始存储库相同的分支、标签等。

不必担心传递 --no-hardlinks,因为不可能在文件系统之间进行硬链接。

每当您想要更新 USB 镜像时,只需安装它并运行以下命令:

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

如果您曾经推送到 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

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.

Whenever you want to update your USB mirror, just mount it and run the following:

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:

# 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
我也只是我 2024-11-23 05:53:28

您可以从任何一个克隆。 USB 驱动器完成后,您可以将其移除。您可以在使用后仔细检查完整性

git fsck --full

You can clone from either. As soon as the usb drive finishes, you can remove it. You can double check integrity after with

git fsck --full
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文