Saving git log number of the current commit in MATLAB
조회 수: 67 (최근 30일)
I wanted to save the current git commit hash of the code that I am currently running. Ideally, something like:
git_hash_string = get_current_git_hash()
and then have it written to some file or displayed to the matlab command line. Is that possible?
Kelly Kearney 2016년 3월 22일
To simply query using the git command via the OS:
[s,git_hash_string] = system('git rev-parse HEAD')
Not sure how this might play with Matlab's git stuff... I haven't touched that, but use git separately to manage several of my Matlab libraries. I assume the underlying git management is the same regardless of whether you initialized the repo in Matlab or outside of it.
추가 답변 (1개)
men8th 2023년 3월 3일
If you are wanting to get a build number then I find the following works well:
system("git describe --tags --first-parent --abbrev=7 --long --dirty --always")
This will return the most recent tag in the repo, followed by the commit hash. I then write this to a file and append with a timestamp. You can then read the value from the file to get a build ID for your toolbox or similar, which can be displayed with the output.
Build: 1.0-4-gb52160e 03-Mar-2023 12:58:39
Inspired by the following from Stack Overflow.