如何添加一个 git 存储库作为另一个 git 存储库的共享依赖项?
我需要类似于子模块的东西,但它作为依赖项存在于主存储库之外。
问题是:
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于每个项目,添加 .git/hooks/pre-commit (并确保它是可执行的):
然后,对于每个项目:
当你进行提交时,它会记录 ~/eagle 的当前 HEAD,以及 git update -eagle 将检查 ~/eagle 中的提交。 (然后,在对其进行任何更改之前,请确保在 ~/eagle 中
git checkout
。)For each project, add .git/hooks/pre-commit (and make sure it's executable):
Then, for each project:
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 yougit checkout <branch>
in ~/eagle before you make any changes to it.)如果
eagle
在ProjX
中没有自己的位置,但是每个
ProjX
都可以使用eagle
的特定版本,那么:
对于每个
ProjX
,您需要:MainProjX
Git 存储库,您可以在其中找到:ProjX
eagle
版本(与ProjX
级别相同)每个目标
MainProjX
父项目是将ProjX
和eagle
的版本放在一起,即记录正确的依赖关系。现在,是的,这是大量的“
eagle
”重复,但如果每个ProjX
都能够使用自己的eagle
版本,那么这是必要的。If
eagle
hasn't its place within aProjX
,but each
ProjX
can use a specific revision ofeagle
,then:
For each
ProjX
, you need to:MainProjX
Git repo, in which you would find:ProjX
eagle
(at the same level thanProjX
)The goal of each
MainProjX
parent project is to keep together the versions ofProjX
andeagle
, that is to record the right dependencies.Now, yes, that is a lot of '
eagle
' duplication, but that is necessary if eachProjX
is able to use its owneagle
revision.