How can I prevent a new MATLAB session from being opened when using mlDiff from git-bash (git for Windows)?

조회 수: 16 (최근 30일)
Apologies if this question is really a "git-bash" question. The problem in short is: when I use mlDiff.exe in cmd.exe on Windows, existing MATLAB sessions are used to lauch the difference window, which I expect and desire. However if I run the same command in git-bash on Windows, it always opens a new MATLAB session, which is undesirable.
git-bash is from a regular git installation (https://gitforwindows.org/ or https://git-scm.com/downloads)
Detail:
I'm using MATLAB's mlDiff.exe on Windows 7 (located at C:/Program Files/MATLAB/R2019b/bin/win64/mlDiff.exe) to compare two .mlapp files (though the file extension is irrelevant to this problem, the same problem is true for .txt and .m files, etc), following the documentation here. When using the command "C:/Program Files/MATLAB/R2019b/bin/win64/mlDiff.exe" PATHTOA PATHTOB in a cmd.exe window, everything works as I'd expected: any open MATLAB session is "used" to open MATLAB's file diff window (which naturally is done very quickly), and if no MATLAB session is open, one is opened and then the diff window also opened. This is also true is git diff is set up to use the above command for .mlapp files, and no issue is present when git diff is executed in cmd.exe.
However if I instead use a git-bash shell to run this command, a new MATLAB session is always opened, which is slow, and made worse as git diff calls this command for each file I want to compare, so as many sessions are opened as files compared. I am using git-bash because it is easier to use for other git operations, the state of the git repo is easier to see at glance, various bash commands are available to me. It was included in the installation of Git (for Windows) and is detected and can be chosen as the default shell for GitHub Desktop (from: https://desktop.github.com/).
  댓글 수: 4
Matthew Thomas
Matthew Thomas 2020년 1월 24일
@stozaki Yes, for that screenshot I used git diff with no arguments. With no additional arguments, git diff compares "the changes you made relative to the index (staging area for the next commit). In other words, the differences are what you could tell Git to further add to the index but you still haven’t." (git docs).
In my project's .gitattributes, I select a shell script to use for comparison of any .mlapp files present in the diff, as they are binary files (line 33):
.gitattributes file
The definition of "MATLAB_diff" is defined in my user's .gitconfig file (lines 9-11):
the .gitconfig settings
The script itself is almost a one liner, and simply takes the neccessary arguments and sends them to mlDiff.exe:
the sh shell script called by git diff

댓글을 달려면 로그인하십시오.

답변 (2개)

stozaki
stozaki 2020년 1월 22일
편집: stozaki 2020년 1월 22일
Could you use "!" in the MATLAB command window?
for example
!git diff fileName
my result of example
>> !git diff lib.m
diff --git a/program/lib.m b/program/lib.m
index b97c00a..df3a439 100644
--- a/program/lib.m
+++ b/program/lib.m
@@ -1 +1,2 @@
-GGG
\ No newline at end of file
+GGG
+FFF
\ No newline at end of file
  댓글 수: 2
Matthew Thomas
Matthew Thomas 2020년 1월 24일
Thank you for the reply stozaki. I can run git commands as external commands in the MATLAB command window as you described with typically no issue. A git diff on regular text files (.txt, .m, etc) works with no issue. My issue comes from the fact that:
  1. I need to use mlDiff.exe for my comparison, as I want to compare .mlapp files before and after I have made some changes. These files are effectively binary files to other comparison programs (including git's default built-in textual diff).
  2. I use mlDiff.exe indirectly via the git-bash shell provided by the "git for windows" installer, as I find there are many benefits of using it over the other shells available to me.
The actual issue itself is described in the original question: note that it is only using mlDiff.exe from git-bash that does not fully work as I exepected, and the unexpected behaviour is not dependent on using git or on which files are compared with mlDiff.exe.
(I actually run git diff on the git-bash shell, and my configuration in the in the .gitconfig file has been set to use mlDiff.exe for any files with the extension .mlapp. However the issue I see occurs when running mlDiff.exe directly from the shell, so ignore git for the purpose of this issue)
Unfortunately your reply not only isn't a solution to my specifc problem, as it does not resolve the issue of a new instance of MATLAB always being created when MATLAB's mlDiff.exe is called by git-bash, but it also does not answer the more general question of "I want to quickly/easily compare .mlapp files between versions/commits that I've tracked in git". This is because for me running !git diff fileName for a .mlapp file causes the comparsion window to be created but "hang", requiring me to Ctrl+c the comparison or close it with the Windows Task Manager.
I expect this occurs because mlDiff.exe requires a MATLAB session to be used in order to function; when I run !git diff in MATLAB's command window, git is run externally, the .mlapp file that has changed is noticed by git and presented (due to my configuration) to mlDiff.exe, which to be executed looks for an existing MATLAB session, finds the one used to run !git diff, opens the mlDiff.exe comparison window, and queues the comparison to be made once that MATLAB session is free. Here is hangs without making a comparison, presumably because the MATLAB session is still waiting for the response from the !git command, which in turn is waiting for the comparison to complete, which is waiting for the response from the !git command, etc, etc.
The new issue of "running mlDiff.exe as an external command in the MATLAB command window" not working can easily be seen with any file comparsion; to test this try something like:
!"C:/Program Files/MATLAB/R2019b/bin/win64/mlDiff.exe" fullpathtotextfile1 fullpathtotextfile2
and it should also hang in the same way as mine has.
Markus Leuthold
Markus Leuthold 2020년 6월 9일
I would also be interested in a proper solution of how to diff mat files. It would be nice to have a tool which allows to show equivalent mat files as identical (despite binary differences due to timestamps) and hence not as different files in git.

댓글을 달려면 로그인하십시오.


Ryan Dunk
Ryan Dunk 2021년 11월 19일

카테고리

Help CenterFile Exchange에서 Source Control Integration에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by