git integration in matlab

31 ビュー (過去 30 日間)
Luca Ferro
Luca Ferro 2023 年 1 月 12 日
編集済み: Luca Ferro 2023 年 3 月 2 日
i'm using git versioning embedded in matlab since a couple of weeks. Since i'm used to linux console commands i prefer to input git commands using matlab command window instead of the UI (plus i need to do some scripting with it).
The syntax is basically the same as git bash with an additional '!':
!git commit -m "Example command syntax"
I had no problem with 99% of the commands, from the most basic ones (push, pull, ...) to more advanced ones (rebase, cherry-pick, ...).
There is one command though:
!git gui
which works fine, meaning that it actually opens the installed git gui and allows you to work within it, BUT you cannot get out of it. The moment you close the gui matlab is stuck in a 'busy' status loop.
Anyone has any idea why and if so how to solve it? I know i could just avoid it and use directly git bash or whatever, but i would still like to know.
Bonus question:
!git rebase -i HEAD~n
works as well but i did not find any way to actually visualize correctly the text file and to edit it. So it is useless.
similarly to before, i just avoid using it and if i need it i use git bash, btu would be nice to know something more about it.

採用された回答

Gayatri Rathod
Gayatri Rathod 2023 年 3 月 1 日
編集済み: Gayatri Rathod 2023 年 3 月 1 日
Hi Luca,
  • It seems that when you launch >>git gui from the MATLAB command window, MATLAB is waiting for the git gui process to finish before it can continue executing commands. However, since git gui is a graphical user interface, it does not terminate until the user closes it manually. This leads to MATLAB being stuck in a loop.
  • One possible solution to this problem is to launch git gui in the background, so that MATLAB does not wait for it to finish. You can do this by adding an ampersand (&) at the end of the command as follows:
!git gui &
  • This should launch git gui in the background and allow you to continue using MATLAB without being stuck in a loop.
  • Another solution to this issue is you can use the system command instead of the ! command to run the git gui command. The system command waits for the process to terminate before continuing execution, so it will not get stuck in a busy status loop.
  • Here is an example of how you can run the git gui command using the system command:
[status, result] = system('git gui');
  • This will launch the git gui process and wait for it to terminate before continuing execution. The status variable will contain the exit status of the process and result variable will contain any output produced by the process.
Answer to your bonus question:
  • when you run >> git rebase -i HEAD~n from the MATLAB command window, it should open the text file in your default text editor. If you want to use a specific text editor, you can set the EDITOR environment variable before running the command:
setenv('EDITOR', 'nano') % Set the editor to nano
!git rebase -i HEAD~n
You can read more about the system and setenv functions from the following documentations: system Function, setenv Function
Hope it helps!
Regards,
Gayatri Rathod
  1 件のコメント
Luca Ferro
Luca Ferro 2023 年 3 月 2 日
編集済み: Luca Ferro 2023 年 3 月 2 日
the first answer regarding git GUI works like a charm.
The second one actually doesnt, i tried and the output is this:
i also tried to add the folder containing the .exe to the path and to set it folllowing this procedure How do I change the default Matlab editor into Notepad++? - MATLAB Answers - MATLAB Central (mathworks.com)
EDIT: i tried usng default windows notepad with the following command:
setenv('EDITOR', 'notepad');
and it works perfectly. I'll stick to regular notepad currently without any hassle.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSource Control についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by