MATLAB Answers

Saving git log number of the current commit in MATLAB

59 views (last 30 days)
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()
dips(git_hash_string)
and then have it written to some file or displayed to the matlab command line. Is that possible?

Accepted Answer

Kelly Kearney
Kelly Kearney on 22 Mar 2016
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.
  4 Comments
Kelly Kearney
Kelly Kearney on 28 Mar 2016
I'd use the -C flag (an option for many git commands, including git-rev-parse):
[s,r] = system('git -C path/to/repo rev-parse HEAD')

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!