我需要类似于子模块的东西,但它们作为依赖项存在于主存储库之外。
问题是:
我正在尝试使用 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 中 checkin 的修订版。
有人知道 Git 中允许这种行为的任何东西吗?
最佳答案
对于每个项目,添加 .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 <branch>
。)
关于git - 如何将 git 存储库添加为另一个 git 存储库的共享依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3347131/