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 ======>" );
    }
相关推荐
lingran__8 小时前
Git 完全指南(二):分支管理
git·分支管理·版本控制·团队协作·多人开发·git flow
必须会一定会10 小时前
Agent Handoff v0.6.0 跨电脑同步:Git、EVENTS.jsonl、CONTEXT.md 使用方法
人工智能·git·ai编程
微三云生态系统架构师-彭丹12 小时前
任务卷轴积分系统架构设计:从任务状态机到合规风控的完整实现
unity·系统架构·游戏引擎
XR技术研习社14 小时前
从 PICO 文档看未来短期内的 Unity 版本选择
unity·游戏引擎·xr·vr
玖玥拾16 小时前
Unity 热更新(一)
unity·游戏引擎
cui_hao_nan16 小时前
Git常用命令1
运维·git
软件黑马王子16 小时前
1.non-MonoBehaviour 单例模式泛型基类
unity·前端框架·c#
xxwl58517 小时前
Git常用命令的学习
git·学习
攻城狮-申17 小时前
git本地分支对齐远程分支
前端·git
不怕犯错,就怕不做1 天前
git prune 自动删除本地记录中那些远程已经不存在的分支引用
linux·服务器·git