主要内容

gitclone

克隆 Git 存储库

自 R2023b 起

    说明

    repo = gitclone(repositoryURL) 将 Git™ 远程存储库 repositoryURL 克隆到当前文件夹中,并返回 matlab.git.GitRepository 对象。

    示例

    repo = gitclone(repositoryURL,folder) 将 Git 远程存储库 repositoryURL 克隆到指定的文件夹 folder 中,并返回 matlab.git.GitRepository 对象。

    示例

    repo = gitclone(___,Name=Value) 将其他选项指定为一个或多个名称-值参量。

    示例

    示例

    全部折叠

    在当前文件夹中克隆存储库。

    repo = gitclone("https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests")
    
    repo = 
    
      GitRepository with properties:
    
         WorkingFolder: "C:\myWorkSpace\newrepo"
             GitFolder: "C:\myWorkSpace\newrepo\.git"
         CurrentBranch: [1×1 GitBranch]  (main)
            LastCommit: [1×1 GitCommit]  (3fa5e35)
               Remotes: [2×1 GitRemote] (origin trunk)
         ModifiedFiles: [0×1 string]
        UntrackedFiles: [0×1 string]
                IsBare: 0
             IsShallow: 0
            IsDetached: 0
            IsWorktree: 0

    要克隆受密码短语保护的存储库,请指定您的 Git 存储库帐户的登录信息,例如 GitHub®。有关详细信息,请参阅克隆受密码短语保护的存储库

    克隆在 GitHub 上托管的受密码短语保护的存储库。

    url = "https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests";
    secrets = loadenv("github.env");
    repo = gitclone(url,Username=secrets("GITHUB_USER"),Token=secrets("GITHUB_TOKEN"))
    
    repo = 
    
      GitRepository with properties:
    
         WorkingFolder: "C:\myWorkSpace\newrepo"
             GitFolder: "C:\myWorkSpace\newrepo\.git"
         CurrentBranch: [1×1 GitBranch]  (main)
            LastCommit: [1×1 GitCommit]  (3fa5e35)
               Remotes: [2×1 GitRemote] (origin trunk)
         ModifiedFiles: [0×1 string]
        UntrackedFiles: [0×1 string]
                IsBare: 0
             IsShallow: 0
            IsDetached: 0
            IsWorktree: 0

    要防止在使用 HTTPS 与远程存储库交互时频繁出现登录提示,请配置 Git 凭据管理器来记住凭据。有关详细信息,请参阅管理 Git 凭据

    克隆指定文件夹中的存储库。

    mkdir("newrepo");
    url = "https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests";
    repo = gitclone(url,"newrepo\")
    
    repo = 
    
      GitRepository with properties:
    
         WorkingFolder: "C:\myWorkSpace\newrepo"
             GitFolder: "C:\myWorkSpace\newrepo\.git"
         CurrentBranch: [1×1 GitBranch]  (main)
            LastCommit: [1×1 GitCommit]  (3fa5e35)
               Remotes: [2×1 GitRemote] (origin trunk)
         ModifiedFiles: [0×1 string]
        UntrackedFiles: [0×1 string]
                IsBare: 0
             IsShallow: 0
            IsDetached: 0
            IsWorktree: 0

    仅克隆最近的提交。

    url = "https://github.com/mathworks/Simulink-Model-Comparison-for-GitHub-Pull-Requests";
    repo = gitclone(url,Depth=1);
    

    验证克隆是否为浅克隆。

    repo.IsShallow
    ans =
    
      logical
    
       1

    输入参数

    全部折叠

    远程存储库的 URL,指定为字符串标量。

    函数在其中克隆存储库的文件夹的路径,指定为字符向量或字符串标量。

    名称-值参数

    全部折叠

    Name1=Value1,...,NameN=ValueN 的形式指定可选参量对组,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

    示例: gitclone(url,Username="myusername",Token="mypersonaltoken",Depth=10)

    Git 存储库帐户的用户名,指定为字符向量或字符串标量。

    数据类型: char | string

    Git 存储库帐户的个人访问令牌,指定为字符向量或字符串标量。

    数据类型: char | string

    浅克隆的深度,指定为非负整数。

    如果不指定深度,gitclone 将执行完整克隆。否则,gitclone 仅克隆由 Depth 指定的提交数量。

    数据类型: single

    以递归方式克隆 Git 子模块的选项,指定为数值或逻辑值 1 (true) 或 0 (false)。

    数据类型: logical

    输出参量

    全部折叠

    Git 存储库,以 matlab.git.GitRepository 对象形式返回。

    版本历史记录

    在 R2023b 中推出