如何使用另一个存储库中的 git 存储库? [英] How do I work with a git repository within another repository?

查看:25
本文介绍了如何使用另一个存储库中的 git 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Git 媒体存储库,我将在其中保存我将在各种项目中使用的所有 JavaScript 和 CSS 主文件和脚本.

I have a Git media repository where I'm keeping all of my JavaScript and CSS master files and scripts that I'll use on various projects.

如果我在自己的 Git 存储库中创建了一个新项目,我如何在我的新项目中使用媒体存储库中的 JavaScript 文件,这样我就不必更新脚本的两个副本我做出改变?

If I create a new project that's in its own Git repository, how do I use JavaScript files from my media repository in my new project in a way that makes it so I don't have to update both copies of the script when I make changes?

推荐答案

关键是git submodules.

开始阅读 Git Community Book用户手册

假设您有存储库 PROJECT1、PROJECT2 和 MEDIA...

Say you have repository PROJECT1, PROJECT2, and MEDIA...

cd /path/to/PROJECT1
git submodule add ssh://path.to.repo/MEDIA
git commit -m "Added Media submodule"

在另一个仓库重复...

Repeat on the other repo...

现在,很酷的一点是,任何时候您向 MEDIA 提交更改时,都可以这样做:

Now, the cool thing is, that any time you commit changes to MEDIA, you can do this:

cd /path/to/PROJECT2/MEDIA
git pull
cd ..
git add MEDIA
git commit -m "Upgraded media to version XYZ"

这只是记录了一个事实,即 PROJECT2 中的 MEDIA 子模块现在处于 XYZ 版本.

This just recorded the fact that the MEDIA submodule WITHIN PROJECT2 is now at version XYZ.

它使您可以 100% 控制每个项目使用的 MEDIA 版本.git submodules 很棒,但您需要尝试并了解它们.

It gives you 100% control over what version of MEDIA each project uses. git submodules are great, but you need to experiment and learn about them.

强大的力量带来了被咬到臀部的大好机会.

With great power comes the great chance to get bitten in the rump.

这篇关于如何使用另一个存储库中的 git 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆