主要内容

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/domain/examplerepo")
    
    repo = 
    
      GitRepository with properties:
    
         WorkingFolder: "C:\myWorkSpace\examplerepo"
             GitFolder: "C:\myWorkSpace\examplerepo\.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/domain/examplerepo";
    repo = gitclone(url,Username="user",Token=getSecret("GITHUB_TOKEN"))
    
    repo = 
    
      GitRepository with properties:
    
         WorkingFolder: "C:\myWorkSpace\examplerepo"
             GitFolder: "C:\myWorkSpace\examplerepo\.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

    如果您使用 SSH 密钥克隆存储库,请改为参阅使用 SSH 密钥克隆存储库

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

    mkdir("newrepo");
    url = "https://github.com/domain/examplerepo";
    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/domain/examplerepo";
    repo = gitclone(url,Depth=1);
    

    验证克隆是否为浅克隆。

    repo.IsShallow
    ans =
    
      logical
    
       1

    您可以使用 SSH 克隆存储库。

    您必须先配置 MATLAB® 以使用 Git SSH 身份验证。有关详细信息,请参阅将 MATLAB 配置为使用 Git SSH 验证

    使用 SSH 密钥克隆在 GitHub 上托管的存储库。

    sshUrl = "git@github.com:user/examplerepo.git.";
    gitclone(sshUrl);

    如果 SSH 密钥受密码短语保护,请指定 SSHKeyPassphrase 参量。

    gitclone(sshUrl,SSHUsername="user",SSHKeyPassphrase=getSecret("SSH_PASS"));

    从 Git 存储库仅克隆 FeatureB 分支。

    url = "https://github.com/domain/examplerepo";
    gitclone(url,Branch="FeatureB",SingleBranch=true);

    输入参数

    全部折叠

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

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

    名称-值参数

    全部折叠

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

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

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

    SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphraseSSHUsername 或指定 UsernameToken

    数据类型: char | string

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

    SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphraseSSHUsername 或指定 UsernameToken

    数据类型: char | string

    自 R2026a 起

    与 SSH 密钥关联的 Git 存储库帐户的用户名,指定为字符向量或字符串标量。

    SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphraseSSHUsername 或指定 UsernameToken

    数据类型: char | string

    自 R2026a 起

    Git 存储库帐户所用 SSH 密钥的密码短语,指定为字符向量或字符串标量。

    SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphraseSSHUsername 或指定 UsernameToken

    数据类型: char | string

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

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

    数据类型: single

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

    数据类型: logical

    自 R2026a 起

    克隆后要切换到的分支的名称,指定为字符串标量或字符向量。

    如果您未指定分支名称,则 gitclone 克隆默认分支,通常称为“main”。

    示例: "BugIssue1032", 'FeatureB'

    数据类型: char | string

    自 R2026a 起

    从存储库克隆单个 Git 分支的选项,指定为数值或逻辑值 1 (true) 或 0 (false)。

    数据类型: logical

    输出参量

    全部折叠

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

    版本历史记录

    在 R2023b 中推出

    全部展开