在 当前仓库根目录下执行命令
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 ======>" );
}