2017-02-16 1 views
6

코드 개발을 위해 MATLABs git support을 사용하고 있으며, 표준 소스 제어 도구를 사용하고 있습니다.MATLAB 명령 창에서 자식 자식

그러나 나는 기본적으로 폴더를 오른쪽 클릭하고 올바른 선택 항목이 발견 될 때까지 메뉴를 탐색하여 작동하는 MATLABs 사용자 인터페이스 만 사용했습니다 (아래 이미지 참조).

매번 메뉴를 탐색해야하는 대신 MATLABs 명령 창에서 git 명령을 실행하는 방법이 있습니까?

enter image description here

답변

4

당신은 MATLAB 내 자식 명령에 대한 시스템 명령 행 탈출 !을 사용할 수 있습니다. 예 :

!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 또 다른 유용한 명령은'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 명령을 자동으로 (명령 행에 출력하지 않음) 호출하고 상태 출력을 사용하여 추가 이점이 있습니다. 자동 빌드 또는 릴리스 프로세스를위한 스크립트를 작성하는 경우 이는 매우 편리합니다.

+0

이것은 매우 흥미 롭습니다! 어떻게 부르죠? 'git ('commit', - 'am', 'mycomment' ')'? 후손에 대한 몇 가지 예를 들려 줄 수 있습니까? –

+1

"명령 스타일"로 호출 할 수 있습니다. 즉, MATLAB 명령 줄에'git commit -m "mycomment"를 입력하거나 함수 스타일로 호출 할 수 있습니다. 즉, [status, cmdout ] = git ('commit', '-m', 'mycomment' ');'. 대화식으로 작업하는 경우 첫 번째 스타일을 사용하지만 자동화 된 빌드 또는 릴리스 스크립트를 작성하는 경우 두 번째 스타일을 사용합니다. –

+0

정말 고마워. 고마워. –

관련 문제