You could script this in your Rakefile, i think it would look something like this:
the most recent git commit: `git log -n 1 --pretty=format:'%h'`
the last recorded git commit: File.read('version-git.txt') rescue ''
the current patch: File.read('version-patch.txt').to_i rescue 0
if the current git commit and last recorded commit don't match, bump the version-patch number. Then add this to your version (app.version = "X.Y.#{patch}").
or, a simpler way to do this, just tack the git commit hash onto the version number:
app.version = "1.2.3-#{`git log -n 1 --pretty=format:'%h'`}"