git integration in matlab

36 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Source Control 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by