Unity Git项目添加子模块

在 当前仓库根目录下执行命令

git submodule add https://github.com/xxx/child.git

检查仓库状态

git status

更新子库

git submodule update --remote

下拉父仓库Git并保住子库也更新

git pull --recurse-submodules

推荐使用 Githubdesktop工具

这样你可以更清楚的看到自己子库关联状态

在Unity本使用脚本调用Git

csharp 复制代码
public static void NewGitCommand( string arguments, string WorkingDirectory = "./" )
    {
        string gitPath = "git";
        ProcessStartInfo startInfo = new ProcessStartInfo( gitPath, arguments )
        {
            WindowStyle = ProcessWindowStyle.Hidden,
            UseShellExecute = false,
            ErrorDialog = false,
            CreateNoWindow = true,
            RedirectStandardError = true,
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            LoadUserProfile = true,
            WorkingDirectory = WorkingDirectory
        };
        var p = new Process { StartInfo = startInfo };
        p.OutputDataReceived += new DataReceivedEventHandler( ( object sender, DataReceivedEventArgs eventArgs ) =>
        {
            if ( !string.IsNullOrEmpty( eventArgs.Data ) )
            {
                Debug.Log(eventArgs.Data);
            }
        } );
        p.ErrorDataReceived += new DataReceivedEventHandler( ( object sender, DataReceivedEventArgs eventArgs ) =>
        {
            if ( !string.IsNullOrEmpty( eventArgs.Data ) )
            {
                Debug.Log( eventArgs.Data );
            }
        } );
        p.Start();
        p.BeginOutputReadLine();
        p.WaitForExit();
        p.Close();
        p.Dispose(); 
    }

案例

csharp 复制代码
   public static void InitOrUpdateSubmodule()
    {
        //Log.PINK( "Begin Update Submodule ======>" );
        NewGitCommand( "submodule update --init --recursive" );
        NewGitCommand( "pull" );
        NewGitCommand( "submodule update" );
        NewGitCommand( "submodule update --remote" );
        AssetDatabase.Refresh();
        //Log.PINK( "End Update Submodule ======>" );
    }
相关推荐
无限进步_10 分钟前
【C语言&数据结构】有效的括号:栈数据结构的经典应用
c语言·开发语言·数据结构·c++·git·github·visual studio
一线灵1 小时前
Axmol 开发环境快速搭建指南 (新)
游戏引擎
不光头强2 小时前
git命令速查表
大数据·git·elasticsearch
大猫和小黄2 小时前
Ubuntu环境下GitBlit安装部署与版本库迁移
linux·运维·git·ubuntu·gitblit
野生yumeko2 小时前
wsl使用git
git·ssh·wsl
初学者_xuan2 小时前
Git&GitLab安装gitlab(rocky系统)
git·gitlab
凤凰战士芭比Q3 小时前
DevOps理念、Git(Git常用命令)、Gitlab仓库
git·gitlab·devops
一线灵3 小时前
跨平台游戏引擎 Axmol-2.11.0 发布
游戏引擎
CoderJia程序员甲3 小时前
GitHub 热榜项目 - 日榜(2025-12-20)
git·ai·开源·llm·github
Robot侠3 小时前
ROS1从入门到精通 2:ROS1核心概念详解(节点、话题、服务一网打尽)
unity·游戏引擎·ros·机器人操作系统