Assuming you are using gem settingslogic to configure your application, put this in your initializers:
git_log = `git log -1 --pretty="format:%H %ci"` if git_log =~ /^([\d\w]+?)\s(.+)$/ Settings[:git_revision] = $1 Settings[:git_update] = $2.strip end
You will have the last git commit SHA in Settings.git_revision and the commit date in Settings.git_update .
Alternatively, you can get the latest tag:
git_tag = `git describe --tags --abbrev=0` Settings[:git_tag] = git_tag.strip if git_tag
It will be available at Settings.git_tag .
Update:
I released a small ruby git-revision stone. With it, you can simply:
"commit: #{Git::Revision.commit} date: #{Git::Revision.date}"
source share