I have a project in php with the use of GIT and there is a file called "version" with inside "1". I want that when i commit the number is incremented. I am using the git hook feature with this script:
num=$(cat version)
num=$(expr 0$num + 1)
echo $num > version
git add -u version
All work fine except that when i check on the ide (phpstorm), the file stay "blue" (not syncronized) so if i click commit i see the file "version" modified.
In short: don't do it at all, do not solve the problem in so wrong way
Answers in How to get the git commit count? and this answer in what is the git equivalent for revision number? and a lot of questions about git describe (variations of second attempt) will give you a lot of ideas and methods getting changeset-count on the fly in pre-build step.
While incremental counter in DAG is, from my POV, is bad and poor concept,
git rev-list --count <revision>
orgit rev-list --all --count
is the most correct method for getting changesets counter