gitclone
语法
说明
将 Git™ 远程存储库 repo = gitclone(repositoryURL)repositoryURL 克隆到当前文件夹中,并返回 matlab.git.GitRepository 对象。
将 Git 远程存储库 repo = gitclone(repositoryURL,folder)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 与基于令牌的身份验证不兼容。指定 SSHKeyPassphrase 和 SSHUsername 或指定 Username 和 Token。
数据类型: char | string
Git 存储库帐户的个人访问令牌,指定为字符向量或字符串标量。
SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphrase 和 SSHUsername 或指定 Username 和 Token。
数据类型: char | string
自 R2026a 起
与 SSH 密钥关联的 Git 存储库帐户的用户名,指定为字符向量或字符串标量。
SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphrase 和 SSHUsername 或指定 Username 和 Token。
数据类型: char | string
自 R2026a 起
Git 存储库帐户所用 SSH 密钥的密码短语,指定为字符向量或字符串标量。
SSH 与基于令牌的身份验证不兼容。指定 SSHKeyPassphrase 和 SSHUsername 或指定 Username 和 Token。
数据类型: 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 中推出当您使用 gitclone、fetch、push 和 pull 函数以编程方式与 Git 存储库交互时,您可以指定 SSH 密码短语。
sshUrl = "git@github.com:user/examplerepo.git."; gitclone(sshUrl,SSHUsername="user",SSHKeyPassphrase=getSecret("SSH_PASS"));
您可以使用 Branch 参量在单个命令中克隆并切换分支。
url = "https://github.com/domain/examplerepo"; gitclone(url,Branch="FeatureB");
您可以使用 SingleBranch 参量从存储库克隆单个分支。
url = "https://github.com/domain/examplerepo"; gitclone(url,Branch="FeatureB",SingleBranch=true);
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)