free hit counter

Friday, July 22, 2011

awk out the git hash

I'm using the first 5 of the git hash as a build number so we can get some automated traceability of developer builds around here.

git log | head | awk '/commit/ {print substr($2,0,5)}' | head -1

ain't unix great?

The first to head at the beginning saves a few milliseconds of your CPU's time by not processing the entire history, and the last call to head -1 makes sure you just get one hash back.

To coerce CMake into stuffing that into a versionInfo.h file you'll need to put the command into a two line script file as CMake execute_process doesn't support a fully piped call like this.

Labels: ,


Blogger rdm said...

I like using:

git log -1 | awk '/commit/{print $2}'

1:23 PM  

Post a Comment

<< Home