I am trying to set up a build server using NAnt tasks. I have a few Git repos that I want to build, but I am having a problem with versioning of the results.
How do version a library (dll) so that each build will use a number for each version? I know that Git has no Revision Number like SVN, but rather a Hash of some sort. I thought of using the Commit date. I will only be building the master on the central server so all commits will be increasing (the merge date).
If I could get the integer representation of the date, I could use this (YYMMDD).
Now I will be using NAnt to do all the cool stuff :), does Git provide a way to get the date of the latest commit?
you want
git log -1 --pretty=format:%cd HEAD
head is optional. It is inferred if not specified.
This gives you the commit time of the latest commit (i.e. HEAD) as a UNIX timestamp (seconds since epoch, i.e. 00:00:00 UTC on 1 January 1970), which should be pretty much what you want:
% git show -s --format='format:%ct' HEAD
1334298121
You can then use date to convert it into the YYMMDD format you mentioned, and also add other stuff:
% date -r `git show -s --format='format:%ct' HEAD` +"foobar-%C%y%m%d.zip"
foobar-20120413.zip
(I added the century in front with %C because that seems the sane thing to do, but you can omit that of course. The foobar and .zip is just an example on how you would directly generate a filename.)
There are also some other formats you can choose from, see git show --help for details:
% git show -s --format='format:%cd' HEAD
Fri Apr 13 14:22:01 2012 +0800
% git show -s --format='format:%cD' HEAD
Fri, 13 Apr 2012 14:22:01 +0800
% git show -s --format='format:%cr' HEAD
3 months ago
% git show -s --format='format:%ct' HEAD
1334298121
% git show -s --format='format:%ci' HEAD
2012-04-13 14:22:01 +0800
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With