Search code examples
phpgitversioning

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.


Solution

  • 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