2

As detailed in How can I find out what version of git I'm running? you can get the git version via

$ git version
git version 2.30.0

But it looks like this is meant to be consumed by humans, not programs. Is that correct? If so is there a "plumbing" git version command that can be used for numerical comparisons of the version?

Timmmm
  • 88,195
  • 71
  • 364
  • 509

2 Answers2

2

I checked the source code. There is a comment about keeping the format of git version stable so it is safe to parse it.

void get_version_info(struct strbuf *buf, int show_build_options)
{
    /*
     * The format of this string should be kept stable for compatibility
     * with external projects that rely on the output of "git version".
     *
     * Always show the version, even if other options are given.
     */
    strbuf_addf(buf, "git version %s\n", git_version_string);
...
Timmmm
  • 88,195
  • 71
  • 364
  • 509
1

Piping?

git --version | awk '{print $3}'
tifrel
  • 421
  • 8
  • 20
  • I was asking if it is *safe* to do this, not *how* to parse that specific value (that bit is trivial). – Timmmm Jun 02 '21 at 19:50
  • You asked for "plumbing" and numeric comparisons, you did not ask for API stability... – tifrel Jun 02 '21 at 19:53
  • That's what "plumbing" commands *are*. They're stable commands that can't be used programmatically. API stability is a prerequisite of running commands programmatically. See https://git-scm.com/book/en/v2/Git-Internals-Plumbing-and-Porcelain – Timmmm Jun 13 '21 at 12:05