Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store git command result into a variable using MATLAB script

Tags:

git

matlab

I'm trying to get the result after executing the git command function !git config --global user.name which outputs my username in the command prompt of my MATLAB.

Now if I assign the same to a variable to use it in another instance I'm getting the below error as shown below.

userName = !git config --global user.name

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

disp(userName);
like image 391
forgottofly Avatar asked Sep 02 '26 15:09

forgottofly


1 Answers

You will need something like

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

etc.

On Windows, depending on different options during setup, you may need to supply the full path to the git binary, e.g.

[~, 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.

like image 169
X Zhang Avatar answered Sep 04 '26 17:09

X Zhang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!