两个Git仓库共享通用代码 [英] Two Git repositories share common code
问题描述
我应该怎么做?是否有更好的方法为公共代码提供第三个存储库?
我不会给出你应该怎么做这个。但我会解释如何完成将第三个存储库与通用代码集成到其他存储库:这是git子模块的工作。 git子模块允许你在指定的路径上引用git仓库的快照:
git submodule add git:// example。 com / repository.git path
然后创建提交。现在给定存储库的快照在路径
中引用。
填充子模块
- 执行
git子模块init
- 执行
git子模块更新
git子模块init
git子模块更新
每个配置的子模块都会更新以匹配它应该看起来像的状态。
将子模块更新为以后的提交
- 切换到子模块
- 执行
git pull
/git fetch
+git checkout
将子模块更新为所需的提交/标记
- 创建一个新提交来更新
.gitmodules中的提交 file
- 创建一个新提交来更新
查看官方手册了解有关子模块的更多信息。
So I have a project which has the client parts and the server parts. I would like the client and the server code to be in different Git repositories for clear separation of the code, however, they share some of the files and ideally, the shared files will always be identical in both client and server.
How should I go about this? Is it better to have the third repository for the common code?
I will not give advice on "How you should go about this". But I'll explain how to accomplish integrating a third repository with common code into the other repositories: This is a job for git submodules. git submodules allow you to reference a snapshot of a git repository at a specified path:
git submodule add git://example.com/repository.git path
Afterwards create a commit. Now a snapshot of the given repository is referenced at path
.
Populating the submodule
- Execute
git submodule init
- Execute
git submodule update
Every configured submodule will be updated to match the state it is supposed to look like.
Updating a submodule to a later commit
- Change into the directory of the submodule
- Perform a
git pull
/git fetch
+git checkout
to update the submodule to the desired commit / tag - Create a new commit to update the commit in the
.gitmodules
file
Take a look at the official manual for further information on submodules.
这篇关于两个Git仓库共享通用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!