我在编程开发中使用MATLAB的Git支持,经常进行提交、推送和所有标准源代码控制操作。
然而,我只使用过MATLAB的用户界面,基本上是通过右键单击文件夹并浏览菜单,直到找到正确的选项为止(见下图)。
有没有办法让MATLAB的命令窗口运行
然而,我只使用过MATLAB的用户界面,基本上是通过右键单击文件夹并浏览菜单,直到找到正确的选项为止(见下图)。
有没有办法让MATLAB的命令窗口运行
git
命令,而不需要每次都浏览菜单?
git
命令,而不需要每次都浏览菜单?
!
来执行git命令。例如:!git status
!git commit -am "Commit some stuff from MATLAB CLI"
!git push
function varargout = git(varargin)
% GIT Execute a git command.
%
% GIT <ARGS>, when executed in command style, executes the git command and
% displays the git outputs at the MATLAB console.
%
% STATUS = GIT(ARG1, ARG2,...), when executed in functional style, executes
% the git command and returns the output status STATUS.
%
% [STATUS, CMDOUT] = GIT(ARG1, ARG2,...), when executed in functional
% style, executes the git command and returns the output status STATUS and
% the git output CMDOUT.
% Check output arguments.
nargoutchk(0,2)
% Specify the location of the git executable.
gitexepath = 'C:\path\to\GIT-2.7.0\bin\git.exe';
% Construct the git command.
cmdstr = strjoin([gitexepath, varargin]);
% Execute the git command.
[status, cmdout] = system(cmdstr);
switch nargout
case 0
disp(cmdout)
case 1
varargout{1} = status;
case 2
varargout{1} = status;
varargout{2} = cmdout;
end
你可以直接在命令行中输入 git 命令,不需要使用 !
或 system
。但它还有另一个优点,就是你可以静默调用 git 命令(不输出到命令行),并带有状态输出。如果你正在创建用于自动化构建或发布流程的脚本,这将非常方便。
git commit -m“mycomment”
,或者你可以使用“函数风格”调用它 - 即使用[status, cmdout] = git('commit', '-m', '"mycomment"');
。如果我只是交互式地工作,我会使用第一种风格,但如果我正在构建自动化构建或发布脚本,我会使用第二种风格。 - Sam Robertsgit status
确保本地的 dev
与远程的 dev
同步;调用 git checkout -b
创建一个发布分支;更新 Contents.m
文件中代码的版本号;检出 dev
和 master
分支,并调用 git merge
从发布分支合并代码;调用 git push
推送 dev
、master
和发布分支到远程;最后检出 master
并调用 makefile 使用 MATLAB Compiler 构建一个工件。 - Sam Robertsstatus
输出来检查每个步骤是否成功。函数式风格确保没有输出到命令行,因此构建脚本可以静默运行。 - Sam Roberts
system
。它允许返回状态和结果:[status, result] = system('git status')
:https://uk.mathworks.com/help/matlab/ref/system.html - tuna_fishrm -rf
)。直接调用“git”似乎是一个更好的主意。 - Ander Biguri