Git学习记录

子模块

介绍

有种情况我们经常会遇到:某个工作中的项目需要包含并使用另一个项目。 也许是第三方库,或者你独立开发的,用于多个父项目的库。 现在问题来了:你想要把它们当做两个独立的项目,同时又想在一个项目中使用另一个。
Git 通过子模块来解决这个问题。子模块允许你将一个 Git 仓库作为另一个 Git 仓库的子目录。 它能让你将另一个仓库克隆到自己的项目中,同时还保持提交的独立。

使用子模块

命令:

git submodule add <url> <文件夹名>

这里的“文件夹名”参数可不指定,默认使用引用的库名
例如:

$ git submodule add git@github.com:huggingface/transformers.git

Cloning into 'D:/AAA-CODE/simulation-OS/transformers'...
Warning: Permanently added the RSA host key for IP address '52.74.223.119' to the list of known hosts.
remote: Enumerating objects: 84444, done.
remote: Counting objects: 100% (288/288), done.
remote: Compressing objects: 100% (170/170), done.
remote: Total 84444 (delta 128), reused 192 (delta 91), pack-reused 84156
Receiving objects: 100% (84444/84444), 67.72 MiB | 5.61 MiB/s, done.
Resolving deltas: 100% (60555/60555), done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory

子模块在github中的效果

使用子模块后,若将此库推送到github等远程库时,子模块文件夹成为一个超链接,点击该文件会跳转到相应的源库。
如下图中的coco_caption和transformers文件夹,点击之后跳转到对应库的github页面。
在这里插入图片描述
官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值