如何在另一个存储库中使用git存储库? [英] How do I work with a git repository within another repository?
问题描述
我有一个Git媒体库,在那里我保存了我将用于各种项目的所有JavaScript和CSS主文件和脚本。
如果我在自己的Git存储库中创建一个新项目,如何在我的新项目中使用来自媒体库的JavaScript文件,在进行更改时,不必更新脚本的两个副本?
好的问题。关键是 git submodules 。 开始阅读 Git Community Book 或用户手册
假设您已存储PROJECT1,PROJECT2和MEDIA存储库...
cd / path / to / PROJECT1
git submodule add ssh://path.to.repo/MEDIA
git commit -mAdded Media submodule
重复其他回购...
现在,最酷的是,任何时候你提交给MEDIA的变更,你都可以这样做:
cd / path / to / PROJECT2 / MEDIA
git pull
cd ..
git add MEDIA
git commit -m将媒体升级到版本XYZ
这只记录了MEDIA子模块WITHIN PROJECT2现在版本为XYZ。
它可以让您100%控制什么MEDIA eac版本h项目使用。 git submodules 非常棒,但您需要试验并了解它们。
随着巨大的动力来临,它将成为陷入困境的好机会。
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.
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?
解决方案Good question. The key is git submodules.
Start reading the Submodules chapter of the Git Community Book or of the Users Manual
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...
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"
This just recorded the fact that the MEDIA submodule WITHIN PROJECT2 is now at version XYZ.
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屋!