MATLAB git by命令窗口

问题描述 投票:7回答:2

我在开发代码时使用MATLABs git support,经常提交,推送和所有标准的源代码控制。

但是,我只使用MATLABs用户界面,基本上可以通过右键单击文件夹并浏览菜单直到找到正确的选项(见下图)。

有没有办法让MATLAB命令窗口运行git命令,而不是每次都需要通过菜单导航?

enter image description here

git matlab
2个回答
5
投票

您可以在MATLAB中使用系统命令行escape ! for git命令。例如:

!git status
!git commit -am "Commit some stuff from MATLAB CLI"
!git push

您需要在系统上安装Git才能使其正常工作。


6
投票

我喜欢在我的路径上添加以下功能:

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命令(没有输出到命令行)和状态输出。如果您要为自动构建或发布过程创建脚本,这将非常方便。

© www.soinside.com 2019 - 2024. All rights reserved.