[英]How can I create a git repository that contains files from another repository?
I have two repositories, A and B. The file structure of A is:我有两个存储库,A 和 B。A 的文件结构是:
/scripts /local-data etc. /scripts /local-data 等
The file structure of B is the same. B的文件结构是一样的。 The difference is that B should be a superset of A. /scripts all scripts/* from A + scripts specific to project B (ie the files from A are on the same directory level as the B-specific scripts)
区别在于 B 应该是 A 的超集。 /scripts all scripts/* from A + 特定于项目 B 的脚本(即来自 A 的文件与特定于 B 的脚本在同一目录级别)
A is open source on github. A是github上的开源。 B is proprietary on a server.
B 在服务器上是专有的。 Whenever A is updated, the A files in B should also be updated.
每当 A 更新时,B 中的 A 文件也应更新。
How do I set this up?我该如何设置?
If you currently have 1 repo you should split it into diffrent repos.如果您目前有 1 个回购,您应该将其拆分为不同的回购。
Use the split
command使用
split
命令
subtree split
git subtree
git-subtree
-Merge
subtrees together orsplit
repository into subtreesgit subtree
git-subtree
- 将子git-subtree
Merge
在一起或split
存储库split
为子树
git subtree split -P <name-of-folder> -b <name-of-new-branch>
Now create submodule or subtree for your repositories.现在为您的存储库创建子模块或子树。
First let's explain what is the main difference between subtree and submodule:首先让我们解释一下子树和子模块之间的主要区别是什么:
both of them are used for having another repo inside existing repo.它们都用于在现有回购中拥有另一个回购。 The main difference is that git
submodule
is independent self-contained repository while subtree
store the date in the parent (original) repo.主要区别在于 git
submodule
是独立的自包含存储库,而subtree
将日期存储在父(原始)存储库中。
Now let's dig in and explain in more details:
Is there any simpler example that I can follow?
有没有我可以遵循的更简单的例子?
Submodule
is a standalone git project so the code will be checked out to a new folder under the root folder and it's not part of your master branch. Submodule
是一个独立的git 项目,所以代码将被检出到根文件夹下的一个新文件夹,它不是你的主分支的一部分。
Your root folder will contain a submodule file and you will have to init && update
it on every clone you make.您的根文件夹将包含一个子模块文件,您必须在您制作的每个克隆上
init && update
它。
# Add the desired submodule to your code base
git submodule add <url>
You must run two commands:您必须运行两个命令:
git submodule init
to initialize your local configuration file, and初始化您的本地配置文件,以及
git submodule update
to fetch all the data from that project and check out the appropriate commit listed in your superproject:从该项目中获取所有数据并查看您的超级项目中列出的相应提交:
So the full script is this:所以完整的脚本是这样的:
git submodule add <url>
git submodule init
git submodule update
You simply need to be in your root folder and then add the submodule folder.您只需要在根文件夹中,然后添加子模块文件夹。
git submodule add <url>
Now when you clone the project you simply need to init and update the submodule现在,当您克隆项目时,您只需要初始化并更新子模块
git submodule init
git submodule update
Git 1.8.2 features a new option --remote Git 1.8.2 提供了一个新选项 --remote
git submodule update --remote --merge
will fetch the latest changes from upstream in each submodule, merge them in, and check out the latest revision of the submodule.将从每个子模块的上游获取最新更改,合并它们,并检查子模块的最新版本。
git subtree
Git subtree allows you to insert any repository as a sub-directory of another one Git子树允许您将任何存储库作为另一个存储库的子目录插入
Very similar to submodule
but the main difference is where your code is managed.与
submodule
非常相似,但主要区别在于代码的管理位置。 In submodules the content is placed inside a separate repo and is managed there which allow you to clone it to many other repos as well.在子模块中,内容被放置在一个单独的存储库中并在那里进行管理,这允许您将其克隆到许多其他存储库。
subtree
is managing the content as part of the root project and not in a separate project. subtree
将内容作为根项目的一部分进行管理,而不是在单独的项目中。
Instead of writing down how to set it up and to understand how to use it you can simply read this excellent post which will explain it all.无需写下如何设置它并了解如何使用它,您只需阅读这篇出色的文章,它将解释这一切。
https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/ https://developer.atlassian.com/blog/2015/05/the-power-of-git-subtree/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.