# How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?

6 messages from 2017-02-02 to 2017-02-04. Participants: Hilco Wijbenga, G. Sylvie Davies, Duy Nguyen.
Thread: https://gitlist.dev/t/45023

## Hilco Wijbenga, 2017-02-02 17:51

Subject: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
Message-ID: <CAE1pOi0-8JnnZbdm9vu1RwTU1mXr7dboLC3ito3LcvK9gkNi_A@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi0-8JnnZbdm9vu1RwTU1mXr7dboLC3ito3LcvK9gkNi_A%40mail.gmail.com

```
Hi all,

I'm trying to get the committer date printed in a custom fashion.
Using "%cI" gets me close:

$ git show --format="%cI | %an" master | head -n 1
2017-01-31T17:02:13-08:00 | Hilco Wijbenga

I would like to get rid of the "-08:00" bit at the end of the
timestamp. According to the "git show" manual I should be able to use
"%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.

$ git show --format="%<(19,trunc)cI | %an" master | head -n 1
cI | Hilco Wijbenga

Mmm, it seems to be recognized as a valid "something" but it's not
working as I had expected. :-) I tried several other versions of this
but no luck. Clearly, I'm misunderstanding the format description. How
do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?

Cheers,
Hilco

```

## G. Sylvie Davies, 2017-02-03 04:19

Subject: Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
Message-ID: <CAAj3zPz8wFc_5dRmM=-jMnqp6a7fGtc4XSyU5meF6mO5me47Dw@mail.gmail.com>
URL: https://gitlist.dev/e/CAAj3zPz8wFc_5dRmM%3D-jMnqp6a7fGtc4XSyU5meF6mO5me47Dw%40mail.gmail.com
In-Reply-To: <CAE1pOi0-8JnnZbdm9vu1RwTU1mXr7dboLC3ito3LcvK9gkNi_A@mail.gmail.com>

```
On Thu, Feb 2, 2017 at 9:51 AM, Hilco Wijbenga <hilco.wijbenga@gmail.com> wrote:
> Hi all,
>
> I'm trying to get the committer date printed in a custom fashion.
> Using "%cI" gets me close:
>
> $ git show --format="%cI | %an" master | head -n 1
> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>
> I would like to get rid of the "-08:00" bit at the end of the
> timestamp. According to the "git show" manual I should be able to use
> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>
> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1
> cI | Hilco Wijbenga
>
> Mmm, it seems to be recognized as a valid "something" but it's not
> working as I had expected. :-) I tried several other versions of this
> but no luck. Clearly, I'm misunderstanding the format description. How
> do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>

Will this work for you?

$ git show -s --pretty='%cd | %an' --date=format:%FT%R:%S
2017-02-02T10:01:36 | G. Sylvie Davies


I have no idea how portable this might be.  As "git help log" says:

         --date=format:...  feeds the format ...  to your system
strftime. Use --date=format:%c to show the date in your system
locale’s preferred format. See the strftime manual for a complete list
of format placeholders.



- Sylvie

```

## Hilco Wijbenga, 2017-02-03 04:32

Subject: Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
Message-ID: <CAE1pOi1agWBHJHmnKkJ7A1EdhJoJausTX7fUeypLbDP6A2FuHQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi1agWBHJHmnKkJ7A1EdhJoJausTX7fUeypLbDP6A2FuHQ%40mail.gmail.com
In-Reply-To: <CAAj3zPz8wFc_5dRmM=-jMnqp6a7fGtc4XSyU5meF6mO5me47Dw@mail.gmail.com>

```
On 2 February 2017 at 20:19, G. Sylvie Davies <sylvie@bit-booster.com> wrote:
> On Thu, Feb 2, 2017 at 9:51 AM, Hilco Wijbenga <hilco.wijbenga@gmail.com> wrote:
>> Hi all,
>>
>> I'm trying to get the committer date printed in a custom fashion.
>> Using "%cI" gets me close:
>>
>> $ git show --format="%cI | %an" master | head -n 1
>> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>>
>> I would like to get rid of the "-08:00" bit at the end of the
>> timestamp. According to the "git show" manual I should be able to use
>> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>>
>> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1
>> cI | Hilco Wijbenga
>>
>> Mmm, it seems to be recognized as a valid "something" but it's not
>> working as I had expected. :-) I tried several other versions of this
>> but no luck. Clearly, I'm misunderstanding the format description. How
>> do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>>
>
> Will this work for you?
>
> $ git show -s --pretty='%cd | %an' --date=format:%FT%R:%S
> 2017-02-02T10:01:36 | G. Sylvie Davies

Ah, that does indeed do exactly what I want. Thank you.

> I have no idea how portable this might be.  As "git help log" says:
>
>          --date=format:...  feeds the format ...  to your system
> strftime. Use --date=format:%c to show the date in your system
> locale’s preferred format. See the strftime manual for a complete list
> of format placeholders.

It should be fine for my purposes.

Any idea why "%<(19,trunc)cl" doesn't work? (Your solution solves my
original problem perfectly but I'd like to understand how I'm
misreading the spec.)

```

## Duy Nguyen, 2017-02-03 08:06

Subject: Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
Message-ID: <CACsJy8DjqrEZ=VaZo6bn4i2r=Wr8k4ExYv48N-rDvfPO=hqpLA@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8DjqrEZ%3DVaZo6bn4i2r%3DWr8k4ExYv48N-rDvfPO%3DhqpLA%40mail.gmail.com
In-Reply-To: <CAE1pOi0-8JnnZbdm9vu1RwTU1mXr7dboLC3ito3LcvK9gkNi_A@mail.gmail.com>

```
On Fri, Feb 3, 2017 at 12:51 AM, Hilco Wijbenga
<hilco.wijbenga@gmail.com> wrote:
> Hi all,
>
> I'm trying to get the committer date printed in a custom fashion.
> Using "%cI" gets me close:
>
> $ git show --format="%cI | %an" master | head -n 1
> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>
> I would like to get rid of the "-08:00" bit at the end of the
> timestamp. According to the "git show" manual I should be able to use
> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>
> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1

You're almost there. Just insert another '%' between "trunc)" and "cI".

> How do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?

You'll get an ellipsis at the end though.. (i.e. 02:13... | Hilco)
-- 
Duy

```

## Hilco Wijbenga, 2017-02-03 17:10

Subject: Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
Message-ID: <CAE1pOi3ThTLSp_0ZJHto4p75Ds5NMGymHrD0ju9axCqA1+NkMA@mail.gmail.com>
URL: https://gitlist.dev/e/CAE1pOi3ThTLSp_0ZJHto4p75Ds5NMGymHrD0ju9axCqA1%2BNkMA%40mail.gmail.com
In-Reply-To: <CACsJy8DjqrEZ=VaZo6bn4i2r=Wr8k4ExYv48N-rDvfPO=hqpLA@mail.gmail.com>

```
On 3 February 2017 at 00:06, Duy Nguyen <pclouds@gmail.com> wrote:
> On Fri, Feb 3, 2017 at 12:51 AM, Hilco Wijbenga
> <hilco.wijbenga@gmail.com> wrote:
>> Hi all,
>>
>> I'm trying to get the committer date printed in a custom fashion.
>> Using "%cI" gets me close:
>>
>> $ git show --format="%cI | %an" master | head -n 1
>> 2017-01-31T17:02:13-08:00 | Hilco Wijbenga
>>
>> I would like to get rid of the "-08:00" bit at the end of the
>> timestamp. According to the "git show" manual I should be able to use
>> "%<(<N>[,trunc|ltrunc|mtrunc])" to drop that last part.
>>
>> $ git show --format="%<(19,trunc)cI | %an" master | head -n 1
>
> You're almost there. Just insert another '%' between "trunc)" and "cI".

Thank you so much! This has been bugging me. :-) Rereading "git help
show", I guess it's implied I should do this but it very much wasn't
clear to me (obviously). I guess I'm too used to the "%19.19s" type of
approach. Maybe there should be some examples?

>> How do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>
> You'll get an ellipsis at the end though.. (i.e. 02:13... | Hilco)

Indeed, that's not very nice. I suppose I can understand the reason
for it but it mostly defeats the purpose of "trunc", doesn't it?
Luckily, Sylvie's solution does exactly what I want.

```

## Duy Nguyen, 2017-02-04 11:49

Subject: Re: How to use git show's "%<(<N>[,trunc|ltrunc|mtrunc])"?
Message-ID: <CACsJy8B3VULFCLyRf9Poeu7UnnZggGyV05-_4LiOO6pHjA++BA@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8B3VULFCLyRf9Poeu7UnnZggGyV05-_4LiOO6pHjA%2B%2BBA%40mail.gmail.com
In-Reply-To: <CAE1pOi3ThTLSp_0ZJHto4p75Ds5NMGymHrD0ju9axCqA1+NkMA@mail.gmail.com>

```
On Sat, Feb 4, 2017 at 12:10 AM, Hilco Wijbenga
<hilco.wijbenga@gmail.com> wrote:
>>> How do I get "2017-01-31T17:02:13 | Hilco Wijbenga" to be output?
>>
>> You'll get an ellipsis at the end though.. (i.e. 02:13... | Hilco)
>
> Indeed, that's not very nice. I suppose I can understand the reason
> for it but it mostly defeats the purpose of "trunc", doesn't it?

It depends. When you truncate a commit subject line, you may want an
indicator that you're not seeing the whole line. For fixed fields like
dates when you expect every string to be truncated, then yes there's
not much point to show the ellipsis.
-- 
Duy

```
