gpt4 book ai didi

git - 使用 MATLAB 脚本将 git 命令结果存储到变量中

转载 作者:行者123 更新时间:2023-12-05 03:16:55 32 4
gpt4 key购买 nike

我试图在执行 git 命令函数 !git config --global user.name 后获取结果,它在我的 MATLAB 命令提示符中输出我的用户名。

现在,如果我将其分配给一个变量以在另一个实例中使用它,我会收到如下错误,如下所示。

userName = !git config --global user.name

Error : Parse error at !git config --global user.name : Usage might be invalid MATLAB syntax

disp(userName);

最佳答案

你需要类似的东西

[~, out.git_hash] = system('git rev-parse --verify HEAD');
[~, out.git_status] = system('git --no-pager diff --no-color');

等等

在 Windows 上,根据安装过程中的不同选项,您可能需要提供 git 二进制文件的完整路径,例如

[~, out.git_hash] = system('"C:/Program Files/Git/mingw64/bin/git"  rev-parse --verify HEAD'); 
[~, out.git_status] = system('"C:/Program Files/Git/mingw64/bin/git" --no-pager diff --no-color');

Just be cautious with pager-related parameters.

关于git - 使用 MATLAB 脚本将 git 命令结果存储到变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74371548/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com