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 ======>" );
    }
相关推荐
程序员爱德华33 分钟前
Git 命令
git
Cry丶14 小时前
Git Rebase 操作备忘
git·rebase
你叶不叶1 天前
abap git 如何从 gitee上在线拉取数据(上一步已经配置好证书)
git·gitee·sap·abapgit
探求虚无1 天前
用 AI 在 Unity 里做一款 RTS:最难的不是生成代码,而是证明它真的能玩
人工智能·unity·游戏引擎
kuroomi2 天前
Git入门
git·kubernetes
daliucheng2 天前
lazygit 上手:日常 git 操作一篇讲完
git
17岁的勇气2 天前
Unity Shader unity文档学习笔记(二十二):shader变体
笔记·学习·unity
codigger2 天前
大厂git提交规范
git·程序员
挖掘狂人2 天前
六条分支,一条主干:我的 Git 分支管理心得
git·后端·程序员
Brookty2 天前
Git与GitHub系统学习|本地Git工作模型:终端与进程、CWD、HEAD/Index/工作树及Git对象
git·github