Nathan H
Nathan H

Reputation: 49371

Generate a version number of my site with git?

I am building a PHP/Yii application. While developing and testing on different machines, I'd like to be able to quickly see in the footers if the version I am seeing is the latest. So basically I want to generate some kind of version number every time I modify something.

I was thinking since I use Git (and GitHub) I could use some of the meta data generated at every commit? How could I achieve this?

Note: I'd like to avoid using command-line stuff as my current hosting won't allow me to do this.

Upvotes: 3

Views: 572

Answers (2)

napolux
napolux

Reputation: 16074

Add a git hook to create a txt file in the root folder of your app to keep track of the version (or tag, or whatever) of the current deployed code.

Just a 30 sec. example (search google for more details and how to use hooks in git) put in the .git/hooks folder a file named pre-commit and add this shell code:

#!/bin/sh
rm version.txt -i
git describe --tags >> version.txt
git add version.txt

Upvotes: 6

Alister Bulman
Alister Bulman

Reputation: 35139

If you deploy with Capistrano, one very serious possibility is to read the 'REVISION' file from the base of the site. If you deploy from a git repo, it will be the commit SHA.

Upvotes: 0

Related Questions