2017-02-16 3 views
6

私はコードを開発する際にMATLABs git supportを使用します。多くの場合、コミットして、すべての標準ソースコントロールを実行します。MATLAB gitコマンドウィンドウで

しかし、私は基本的にフォルダを右クリックし、適切な選択肢が見つかるまでメニューをナビゲートすることによって動作するMATLABのユーザーインターフェイスを使用しました(下の画像を参照)。

いつでもメニューをナビゲートする必要はなく、gitコマンドをMATLABコマンドウィンドウで実行する方法はありますか?

enter image description here

答えて

4

あなたはMATLAB内でのgitコマンドのためのシステムのコマンドラインエスケープ!を使用することができます。例:

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

これが機能するには、システムにGitをインストールする必要があります。

+0

ああ。これはMathworksのどこかで文書化されていますか? –

+3

Gitを特に使用するわけではありませんが、はいです:https://uk.mathworks.com/help/matlab/matlab_external/run-external-commands-scripts-and-programs.html もう1つの便利なコマンドは 'system'です。ステータスと結果を返すことができます: '[status、result] = system( 'git status')':https://uk.mathworks.com/help/matlab/ref/system.html –

+0

私はaccidet私の他の質問:https://stackoverflow.com/questions/42271641/matlab-git-pullを解決します。どうかお気軽にお答えください。 –

5

私は私の道の上に以下の機能を置くのが好き:

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 

あなたはその後、!またはsystemを使用せずに、コマンドラインで直接のgitコマンドを入力することができます。しかし、gitコマンドを静かに(コマンドラインには出力せず)、ステータス出力でも呼び出すことができるという利点があります。自動ビルドまたはリリースプロセス用のスクリプトを作成する場合は、これは非常に便利です。

+0

これは非常に興味深い!どのように呼びますか? 'git( 'commit'、 - 'am'、 'mycomment' ')'?あなたは後世のいくつかの例を挙げることができますか? –

+1

"コマンドスタイル"で呼び出すことができます。つまり、MATLABコマンドラインで 'git commit -m" mycomment "'と入力するか、関数スタイルで呼び出すことができます。つまり、[status、cmdout ] = git( 'commit'、 '-m'、 'mycomment' '); '。インタラクティブに作業している場合は最初のスタイルを使用しますが、自動化されたビルドスクリプトやリリーススクリプトを作成する場合は、2番目のスクリプトを使用します。 –

+0

これは素晴らしいです、ありがとうございます。 –

関連する問題