I wanted to have a git log format, which is essentially the oneline
pretty format, but including the author email.
Since I'm trying to make the format as compact as possible, in addition to using the short hash, I'd like to use the author email truncated at the @
.
Right now, my format is:
%h | %<(10,trunc)%ae | %s
which yields an output similar to:
2821c992ff | dev12@yi.. | a commit
e45d9c934b | dev13abc.. | another commit
This is acceptable, since the author emails are 10 chars max before the @
, but the email end format is somewhat messy.
I'm looking for the simplest way to truncate at the @
, yielding an output like:
2821c992ff | dev12 | a commit
e45d9c934b | dev13abc | another commit
The crucial concept is to truncate at the @
.
As refence, I'm using the latest git (2.11.x).
With Git 2.25 (Q1 2020), the custom format for "git log --format=<format>
" learned the l/L
placeholder that is similar to e/E
that fills in the e-mail address, but only the local part on the left side of '@
'.
See commit d8b8217 (29 Oct 2019), and commit 45e206f, commit 2ae4944 (24 Oct 2019) by Prarit Bhargava (``).
(Merged by Junio C Hamano -- gitster
-- in commit c22f63c, 10 Nov 2019)
pretty
: add "%aL
" etc. to show local-part of email addressesSigned-off-by: Prarit Bhargava
In many projects the number of contributors is low enough that users know each other and the full email address doesn't need to be displayed.
Displaying only the author's username saves a lot of columns on the screen.
Existing '
e/E
' (as in "%ae
" and "%aE
") placeholders would show the author's address as "[email protected]
", which would waste columns to show the same domain-part for all contributors when used in a project internal to redhat.
Introduce '
l/L
' placeholders that strip '@
' and domain part from the e-mail address.
Note, as noted in Git 2.28 (Q3 2020), %cl
/%cL
stand for committer, not author.
See commit 087bf54 (23 Jun 2020) by Miroslav Koškár (mkoskar
).
(Merged by Junio C Hamano -- gitster
-- in commit 5c61d10, 06 Jul 2020)
doc
: fix author vs. committer copy/paste errorSigned-off-by: Miroslav Koškár
I think you need GNU Awk gensub()
function to remove everything after the @
part from column 2,
awk 'BEGIN{FS=OFS="|"}{$2=gensub(/@.*$/," ","g",$2);}1' file
2821c992ff | dev12.. | a commit
e45d9c934b | dev13abc.. | another commit
Or in a pipe-line(|
) do,
.. | awk 'BEGIN{FS=OFS="|"}{$2=gensub(/@.*$/,".. ","g",$2);}1'
(or) as you indicated in the comments below, if you do not want the ..
part, remove it from the substitution part in gensub()
as
.. | awk 'BEGIN{FS=OFS="|"}{$2=gensub(/@.*$/," ","g",$2);}1'
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