如何添加一个 git 存储库作为另一个 git 存储库的共享依赖项?

发布于 2024-09-11 07:26:34 字数 1316 浏览 11 评论 0原文

我需要类似于子模块的东西,但它作为依赖项存在于主存储库之外。

问题是

我正在尝试使用 Git(以一种非常尴尬的方式)来管理 CAD 工具 (Cadsoft Eagle) 的设计文件,并且我很难弄清楚是否存在是一种使用 git 子模块来管理每个项目对 CAD 工具共享库的依赖关系的方法。

我使用的文件夹结构如下:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
    Proj1/
        .git/
         <design files>

在这种情况下,将 eagle.git 存储库添加为每个项目的 git 子模块是没有意义的。

但是,我仍然需要一种方法来快照“eagle.git”存储库的当前状态,以便将来更新该库时,可以回滚它以访问正在使用的库文件的特定版本Proj[x] 已提交。

理想情况下,我想要如下所示的内容:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
        **eagle** <-- something that acts like a submodule  
                      but which actually points to ~/eagle/
    Proj1/
        .git/
         <design files>
         **eagle** <-- something that acts like a submodule  
                       but which actually points to ~/eagle/

我希望能够:

cd ~/projects/Proj0
git submodule update

并使 ~/eagle/ 目录自动回滚到签入 Proj0 的修订版本。

有人知道 Git 中可以允许这种行为的任何东西吗?

I need something akin to submodules, but which exist outside the main repository as a dependency.

Here's the problem:

I'm trying to use Git (in a REALLY awkward way) to manage design files for a CAD tool (Cadsoft Eagle), and I'm having a hard time figuring out if there is a way to use git submodules to manage each project's dependency upon the CAD tool's shared library.

I'm using a folder structure like this:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
    Proj1/
        .git/
         <design files>

In this case, it doesn't make sense to add the eagle.git repository as a git submodule for each project.

However, I still need a way to snapshot the current state of the "eagle.git" repository so that if the library is updated in the future, it can be rolled back to access the specific revision of the library files which were being used when the Proj[x] was committed.

Ideally, I'd like something like the following:

~/eagle/ <-- Main library used by multiple projects
    .git/     
    <library files>

~/projects/ <-- Projects folder
    Proj0/
        .git/
        <design files>
        **eagle** <-- something that acts like a submodule  
                      but which actually points to ~/eagle/
    Proj1/
        .git/
         <design files>
         **eagle** <-- something that acts like a submodule  
                       but which actually points to ~/eagle/

I'd like to be able to:

cd ~/projects/Proj0
git submodule update

and have the ~/eagle/ directory automatically roll back to the revision checked into Proj0.

Anybody know of anything in Git that could allow for this kind of behavior?

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

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

发布评论

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

评论(2

洒一地阳光 2024-09-18 07:26:34

对于每个项目,添加 .git/hooks/pre-commit (并确保它是可执行的):

#!/bin/sh
git --git-dir=~/eagle/.git log -1 --pretty=format:%H >.eagle_rev
git add .eagle_rev

然后,对于每个项目:

git config alias.update-eagle '!git --git-dir=~/eagle/.git --work-tree=~/eagle checkout -q $(<.eagle_rev)'

当你进行提交时,它会记录 ~/eagle 的当前 HEAD,以及 git update -eagle 将检查 ~/eagle 中的提交。 (然后,在对其进行任何更改之前,请确保在 ~/eagle 中 git checkout 。)

For each project, add .git/hooks/pre-commit (and make sure it's executable):

#!/bin/sh
git --git-dir=~/eagle/.git log -1 --pretty=format:%H >.eagle_rev
git add .eagle_rev

Then, for each project:

git config alias.update-eagle '!git --git-dir=~/eagle/.git --work-tree=~/eagle checkout -q $(<.eagle_rev)'

When you make a commit, it will record the current HEAD of ~/eagle, and git update-eagle will check out that commit in ~/eagle. (Then just make sure you git checkout <branch> in ~/eagle before you make any changes to it.)

人生戏 2024-09-18 07:26:34

如果 eagleProjX 中没有自己的位置,
但是每个ProjX都可以使用eagle的特定版本,
那么:

对于每个 ProjX,您需要:

  • 有一个 MainProjX Git 存储库,您可以在其中找到:
    • 一个ProjX
    • eagle 版本(ProjX 级别相同)

每个目标MainProjX 父项目是将 ProjXeagle 的版本放在一起,即记录正确的依赖关系。

~/projects/ <-- Projects folder
    MainProj0
      Proj0/
          .git/
          <design files>
      eagle/
          .git/
          <library files>

    MainProj1
      Proj1/
          .git/
          <design files>
      eagle/
          .git/
          <library files>

现在,是的,这是大量的“eagle”重复,但如果每个 ProjX 都能够使用自己的 eagle 版本,那么这是必要的。

If eagle hasn't its place within a ProjX,
but each ProjX can use a specific revision of eagle,
then:

For each ProjX, you need to:

  • have a MainProjX Git repo, in which you would find:
    • a ProjX
    • a version of eagle (at the same level than ProjX)

The goal of each MainProjX parent project is to keep together the versions of ProjX and eagle, that is to record the right dependencies.

~/projects/ <-- Projects folder
    MainProj0
      Proj0/
          .git/
          <design files>
      eagle/
          .git/
          <library files>

    MainProj1
      Proj1/
          .git/
          <design files>
      eagle/
          .git/
          <library files>

Now, yes, that is a lot of 'eagle' duplication, but that is necessary if each ProjX is able to use its own eagle revision.

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