Created
March 4, 2024 23:45
-
-
Save sago35/25e43ec2a4862ccb32a6bbde4f443146 to your computer and use it in GitHub Desktop.
git-log-pretty-cheatsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# 以下の Perl version として作成 | |
# git-logのPRETTY FORMATの動くチートシートを作った | |
# https://zenn.dev/fujimura/articles/79b27b80e14e2e | |
use strict; | |
use warnings; | |
my $CLEAR = "\e[0m"; | |
my $BOLD = "\e[1m"; | |
my $COLORS = { | |
black => "\e[30m", | |
red => "\e[31m", | |
green => "\e[32m", | |
yellow => "\e[33m", | |
blue => "\e[34m", | |
magenta => "\e[35m", | |
cyan => "\e[36m", | |
white => "\e[37m", | |
}; | |
my $colors = {}; | |
foreach my $key (keys %$COLORS) { | |
my $value = $COLORS->{$key}; | |
$colors->{$key} = sub { | |
return "$value$_[0]$CLEAR"; | |
} | |
} | |
my $pretty_format = sprintf "%s %s %%s\n", $colors->{red}('%h'), $colors->{yellow}('%aN'); | |
my @lines = <DATA>; | |
chomp @lines; | |
for (my $i = 0; $i < @lines; $i += 3) { | |
next if $lines[$i] =~ /^%G./; | |
$pretty_format .= sprintf "%s\t%s\t%s\n", | |
$colors->{magenta}("%" . $lines[$i+0]), | |
$colors->{cyan}($lines[$i+1]), $lines[$i+0]; | |
} | |
system('git', 'log', '--pretty=format:' . $pretty_format); | |
# Taken from https://git-scm.com/docs/pretty-formats/2.44.0 | |
__END__ | |
%H | |
commit hash | |
%h | |
abbreviated commit hash | |
%T | |
tree hash | |
%t | |
abbreviated tree hash | |
%P | |
parent hashes | |
%p | |
abbreviated parent hashes | |
%an | |
author name | |
%aN | |
author name (respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%ae | |
author email | |
%aE | |
author email (respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%al | |
author email local-part (the part before the @ sign) | |
%aL | |
author local-part (see %al) respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%ad | |
author date (format respects --date= option) | |
%aD | |
author date, RFC2822 style | |
%ar | |
author date, relative | |
%at | |
author date, UNIX timestamp | |
%ai | |
author date, ISO 8601-like format | |
%aI | |
author date, strict ISO 8601 format | |
%as | |
author date, short format (YYYY-MM-DD) | |
%ah | |
author date, human style (like the --date=human option of git-rev-list[1]) | |
%cn | |
committer name | |
%cN | |
committer name (respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%ce | |
committer email | |
%cE | |
committer email (respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%cl | |
committer email local-part (the part before the @ sign) | |
%cL | |
committer local-part (see %cl) respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%cd | |
committer date (format respects --date= option) | |
%cD | |
committer date, RFC2822 style | |
%cr | |
committer date, relative | |
%ct | |
committer date, UNIX timestamp | |
%ci | |
committer date, ISO 8601-like format | |
%cI | |
committer date, strict ISO 8601 format | |
%cs | |
committer date, short format (YYYY-MM-DD) | |
%ch | |
committer date, human style (like the --date=human option of git-rev-list[1]) | |
%d | |
ref names, like the --decorate option of git-log[1] | |
%D | |
ref names without the " (", ")" wrapping. | |
%S | |
ref name given on the command line by which the commit was reached (like git log --source), only works with git log | |
%e | |
encoding | |
%s | |
subject | |
%f | |
sanitized subject line, suitable for a filename | |
%b | |
body | |
%B | |
raw body (unwrapped subject and body) | |
%N | |
commit notes | |
%GG | |
raw verification message from GPG for a signed commit | |
%G? | |
show "G" for a good (valid) signature, "B" for a bad signature, "U" for a good signature with unknown validity, "X" for a good signature that has expired, "Y" for a good signature made by an expired key, "R" for a good signature made by a revoked key, "E" if the signature cannot be checked (e.g. missing key) and "N" for no signature | |
%GS | |
show the name of the signer for a signed commit | |
%GK | |
show the key used to sign a signed commit | |
%GF | |
show the fingerprint of the key used to sign a signed commit | |
%GP | |
show the fingerprint of the primary key whose subkey was used to sign a signed commit | |
%GT | |
show the trust level for the key used to sign a signed commit | |
%gD | |
reflog selector, e.g., refs/stash@{1} or refs/stash@{2 minutes ago}; the format follows the rules described for the -g option. The portion before the @ is the refname as given on the command line (so git log -g refs/heads/master would yield refs/heads/master@{0}). | |
%gd | |
shortened reflog selector; same as %gD, but the refname portion is shortened for human readability (so refs/heads/master becomes just master). | |
%gn | |
reflog identity name | |
%gN | |
reflog identity name (respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%ge | |
reflog identity email | |
%gE | |
reflog identity email (respecting .mailmap, see git-shortlog[1] or git-blame[1]) | |
%gs | |
reflog subject |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
以下の Perl version として作成
git-logのPRETTY FORMATの動くチートシートを作った
https://zenn.dev/fujimura/articles/79b27b80e14e2e