# Add compiled date to git --version output?

5 messages from 2009-09-18 to 2009-09-18. Participants: Nazri Ramliy, Brian Gernhardt, David Aguilar, Junio C Hamano.
Thread: https://gitlist.dev/t/20996

## Nazri Ramliy, 2009-09-18 04:17

Subject: Add compiled date to git --version output?
Message-ID: <544dda350909172117r44761577m11e7d30a1a5d0c91@mail.gmail.com>
URL: https://gitlist.dev/e/544dda350909172117r44761577m11e7d30a1a5d0c91%40mail.gmail.com

```
Sometimes I wanted to know how outdated git is on my system.

Coming up with a script to parse "git --version" output to get the SHA1,
and compare that to master's SHA1 seemed a little overkill compared to
this:

diff --git a/help.c b/help.c
index 294337e..bc83491 100644
--- a/help.c
+++ b/help.c
@@ -361,6 +361,9 @@ const char *help_unknown_cmd(const char *cmd)

 int cmd_version(int argc, const char **argv, const char *prefix)
 {
-       printf("git version %s\n", git_version_string);
+       printf("git version %s compiled %s %s\n",
+                       git_version_string,
+                       __DATE__,
+                       __TIME__);
        return 0;
 }

With this, git --version gives:

        git version 1.6.5.rc1.19.g8426.dirty compiled Sep 18 2009 12:03:29

Thoughts?

Nazri

```

## Brian Gernhardt, 2009-09-18 04:43

Subject: Re: Add compiled date to git --version output?
Message-ID: <F73940A6-02F5-48EE-BD11-FCEC5B21B054@gernhardtsoftware.com>
URL: https://gitlist.dev/e/F73940A6-02F5-48EE-BD11-FCEC5B21B054%40gernhardtsoftware.com
In-Reply-To: <544dda350909172117r44761577m11e7d30a1a5d0c91@mail.gmail.com>

```

On Sep 18, 2009, at 12:17 AM, Nazri Ramliy wrote:

> +       printf("git version %s compiled %s %s\n",
> +                       git_version_string,
> +                       __DATE__,
> +                       __TIME__);

> Thoughts?

Any idea how compatible that is?  Sure, it'll work with GCC's cpp, but  
we try to work with a huge variety of compilers.

At the very least you might want to wrap it all in #ifdefs or something:

#if defined(__DATE__) && defined(__TIME__)
/* your version */
#else
/* old version */
#endif

(Or play fun tricks with #ifndef ... #define, but then you also have  
to play with the format string or something.)

~~Brian

```

## David Aguilar, 2009-09-18 05:03

Subject: Re: Add compiled date to git --version output?
Message-ID: <20090918050351.GA11242@gmail.com>
URL: https://gitlist.dev/e/20090918050351.GA11242%40gmail.com
In-Reply-To: <544dda350909172117r44761577m11e7d30a1a5d0c91@mail.gmail.com>

```
On Fri, Sep 18, 2009 at 12:17:48PM +0800, Nazri Ramliy wrote:
> Sometimes I wanted to know how outdated git is on my system.

	$ ls -la $(which git)


> Coming up with a script to parse "git --version" output to get the SHA1,
> and compare that to master's SHA1 seemed a little overkill compared to
> this:
> 
> diff --git a/help.c b/help.c
> index 294337e..bc83491 100644
> --- a/help.c
> +++ b/help.c
> @@ -361,6 +361,9 @@ const char *help_unknown_cmd(const char *cmd)
> 
>  int cmd_version(int argc, const char **argv, const char *prefix)
>  {
> -       printf("git version %s\n", git_version_string);
> +       printf("git version %s compiled %s %s\n",
> +                       git_version_string,
> +                       __DATE__,
> +                       __TIME__);
>         return 0;
>  }
> 
> With this, git --version gives:
> 
>         git version 1.6.5.rc1.19.g8426.dirty compiled Sep 18 2009 12:03:29
> 
> Thoughts?

For whatever it's worth, I would feel more comfortable if this
were guarded behind an option e.g. 'git version --date'.

I suspect that there are a fair number of scripts out there
parsing the output of 'git version'.  'git version' is not
plumbing but we still might want to avoid breaking them.

Is it better to say "compiled on $date" or "compiled $date"?

It's meant to be informational (aka not an actual English
sentence) so I guess it could go either way; "compiled on"
is a little more proper, though.

What about "born on $date" since it gives users a subliminal
suggestion that they should consider upgrading to a fresh git?
;)


-- 

	David

```

## Junio C Hamano, 2009-09-18 05:07

Subject: Re: Add compiled date to git --version output?
Message-ID: <7v8wgchmcc.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v8wgchmcc.fsf%40alter.siamese.dyndns.org
In-Reply-To: <544dda350909172117r44761577m11e7d30a1a5d0c91@mail.gmail.com>

```
Nazri Ramliy <ayiehere@gmail.com> writes:

> Sometimes I wanted to know how outdated git is on my system.
>
> Coming up with a script to parse "git --version" output to get the SHA1,
> and compare that to master's SHA1 seemed a little overkill compared to
> this:
>
> diff --git a/help.c b/help.c
> index 294337e..bc83491 100644
> --- a/help.c
> +++ b/help.c
> @@ -361,6 +361,9 @@ const char *help_unknown_cmd(const char *cmd)
>
>  int cmd_version(int argc, const char **argv, const char *prefix)
>  {
> -       printf("git version %s\n", git_version_string);
> +       printf("git version %s compiled %s %s\n",
> +                       git_version_string,
> +                       __DATE__,
> +                       __TIME__);
>         return 0;
>  }
>
> With this, git --version gives:
>
>         git version 1.6.5.rc1.19.g8426.dirty compiled Sep 18 2009 12:03:29
>
> Thoughts?

It's open source, so you are welcome to do that to your binary.

Personally, I do not want it.  My build scripts depend on the version
string at the end if the output to omit re-building what is already
installed.

Seriously, the version number is useful to track down the bug, and perhaps
your compiler and library versions might be useful to help diagnose build
related errors, but when would that __DATE__/__TIME__ be useful more than
what "ls -l /usr/bin/git" would give you?

```

## Nazri Ramliy, 2009-09-18 06:04

Subject: Re: Add compiled date to git --version output?
Message-ID: <544dda350909172304i2d603719ra44bef520389f024@mail.gmail.com>
URL: https://gitlist.dev/e/544dda350909172304i2d603719ra44bef520389f024%40mail.gmail.com
In-Reply-To: <7v8wgchmcc.fsf@alter.siamese.dyndns.org>

```
Thanks for the input guys, I've come to the conclusion that the extra
effort needed to properly implement this is not worth the benefit of
the outcome.

As some of you mentioned, ls -l `which git` is better suited for the
purpose, and that can be done universally for all files where the
filesystem stores the create timestamp of each.

nazri.

```
