Rails 3 app, How to get GIT version and update website?

前端 未结 4 1978
别那么骄傲
别那么骄傲 2021-02-08 17:59

I am deploying my rails 3 app using capistrano, and I want to get the git version (and date information) and update my website\'s footer with this.

How can I do this?

4条回答
  •  面向向阳花
    2021-02-08 18:55

    To people that doesn't use capistrano, a prettier one:

    On config/initializers/git_info.rb:

    GIT_BRANCH = `git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`
    GIT_COMMIT = `git log --pretty=format:'%h' -n 1`
    GIT_COMMIT_TIMESTAMP = `git log --pretty=format:'%ct' -n 1`
    

    The second one gives the sha in prettier form (ex: 4df21c0).

    The third one returns the UNIX TIMESTAMP, that I format using Time/DateTime later.

提交回复
热议问题