0

The answer to a question here states:

Most version control systems have a way to automatically inject the revision number on check-in for instance.

How do I do this with Git? Or have I missed the point (not what they meant by VCS)?

SimpleOne
  • 1,066
  • 3
  • 12
  • 29
  • 1
    Should rather use hashing in the name and have it long cache expiry. – Rikin May 11 '18 at 19:37
  • You could probably use a git hook for that but...I don't think that's really the point of a VCS and it's a bit of a hack. It sounds more of a build task once you're preparing for a release, you will have your build system do that for you. It's a nice separation in responsibility - Git remains in charge of just saying what the file contents are, the build system is in charge of outputting a runnable artefact. – VLAZ May 11 '18 at 19:55

1 Answers1

0

That definitely is what they meant by VCS. However, git doesn't have revision numbers, and you can't predict the commit hash before making the commit, which is definitely too late to inject anything inside.

What you can do is inject current commit hash into config files in the deployment flow. E.g. in the script pushing files to the server say git rev-parse --short HEAD >revision and then use this file's content. Alternatively, if you have got repo in the server, run git rev-parse --short HEAD on startup.

Frax
  • 5,015
  • 2
  • 17
  • 19
  • How do I get that revision into the html? I'm quite new to git. – SimpleOne May 11 '18 at 20:39
  • 1
    That depends on the framework you use, just pass the revision number as a template parameter. Or do you need it in static html files? If this is the case, perhaps put some placeholder in this place and replace it with sed, e.g. `sed -i "s/###REVISION###/$(cat revision)/g" *.html`. – Frax May 12 '18 at 09:17
  • Hi @SimpleOne, was my answer helpful? If so, you may consider [marking it as accepted](https://stackoverflow.com/help/someone-answers). If not, you can still try asking for clarification or elaboration. – Frax May 27 '18 at 17:37