Last Updated: February 25, 2016
·
2.372K
· dpaluy

Get current Git commit version in Rails app

If you need to get your Git version, do the following:

commit = `git rev-parse HEAD`
puts commit  #=> 0cfc01d47d1753bb1e55fb347644239b70ab2772

#short version
commit = `git rev-parse --short HEAD`
puts commit  #=> 0cfc01d

If you need to get a Fit version from Github repository, you can use gem "github_api" https://github.com/peter-murach/github

github = Github.new auth_token
commits = github.repos.commits.all 'username', 'project'
commits.first['sha']