Raise version when commit

378 Views Asked by At

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.

1

There are 1 best solutions below

1
On
  1. You must to ignore this file and don't have it in repo
  2. You reinvented the wheel and gonna duplicate a) already existing inside Git b) always and automatically correct information

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> or git rev-list --all --count is the most correct method for getting changesets counter