BlueRoseNote/03-UnrealEngine/流程管理与部署/版本管理/使用Git SubModule来管理开源插件.md
2023-06-29 11:55:02 +08:00

37 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 使用Git SubModule来管理开源插件
date: 2022-08-10 13:55:20
excerpt:
tags: Git
rating: ⭐
---
# 前言
之前有考虑过将项目中自己的移植版AdvancedLocomotionSystem v4换成社区维护版本[ALS-Community](https://github.com/dyanikoglu/ALS-Community)。众所周知,如果主仓库下存在子.git文件夹那子.git文件夹中的改动主仓库是无法检测到的除非把子.git删除。但我既想在主项目中使用git来管理版本又想在插件中保留git信息以方便从github中获取最新的改动。查了一番资料最后发现git已经给出了解决方案Git SubModule。
## 用法
### submodule add
第一步添加submodule命令为
>git submodule add url path
例如:
>git submodule add https://github.com/dyanikoglu/ALS-Community.git Plugins/ALS-Community
执行完之后就会出现.gitmodules文件里面主要是git submodule相关信息。
![](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Images/Git-SubModule2.png)
同时还会有一个与子模块同名的文件出现它记录Commit的hash值如果子模块的Commit发生变动主仓库的这个文件都会出现改动。
![](https://cdn.jsdelivr.net/gh/blueroseslol/ImageBag@latest/ImageBag/Images/Git-SubModule1.png)
在上传github之后点击这个文件就会自动跳转到之前定义的仓库url。
### Clone
默认的clone可能会出现submodule为空的情况。这是需要在Clone后面加上`--recurse-submodules`选项。例如:
>git clone --recurse-submodules https://github.com/XXXX/XXXX
## 个人建议
因为考虑到后续可能会修改插件所以还是建议先fork一下目标仓库之后git submodule add这个仓库。这样依然可以通过添加原仓库Remote的方式来更新代码。
最近本人开始使用Obsidian笔记把Github图床仓库作为子模块下载到Asset目录下或许也是个不错的选择。
### Git-Fork
这里我推荐git-fork这个软件免费小巧又好用。特别是打开源码仓库的时候速度比SourceTree快多了。默认情况下已经可以自动下载submodule。
另外说一点,点击标签页右边的+,除了会显示之前打开过的仓库之外,还会显示这些仓库目录下的子仓库,可以说是相当方便了。