-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithelpers
More file actions
92 lines (74 loc) · 2.24 KB
/
githelpers
File metadata and controls
92 lines (74 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# All credit to Gary Bernhardt for this.
# Log output:
#
# * 51c333e (12 days) <Gary Bernhardt> add vim-eunuch
#
# The time massaging regexes start with ^[^<]* because that ensures that they
# only operate before the first "<". That "<" will be the beginning of the
# author name, ensuring that we don't destroy anything in the commit message
# that looks like time.
#
# The log format uses } characters between each field, and `column` is later
# used to split on them. A } in the commit subject or any other field will
# break this.
HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
show_git_head() {
pretty_git_log -1
git show -p --pretty="tformat:"
}
pretty_git_log() {
WIDTH=$(tput cols)
git log --color=always --graph --pretty="tformat:${FORMAT}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Line columns up based on } delimiter
column -s '}' -t |
# Page only if we need to
less -FXRS
}
# And now I add my own git helper shell functions:
git_checkpoint() {
git add --all
git commit --message "wip: $(uuidgen)"
}
histogram() {
# This takes <int> <value> rows and gives <value> <histo>
perl -lane 'print $F[1], "\t", "=" x ($F[0] / 5)'
}
# From Ally PIechowski
# https://piechowski.io/post/git-commands-before-reading-code/
git_most_changes() {
git log --format=format: --name-only --since="1 year ago" \
| grep -v '^$' \
| sort \
| uniq -c \
| sort -nr \
| head -20
}
git_who_made_this() {
git shortlog -sn --no-merges
}
git_bug_clusters() {
git log -i -E --grep="fix|bug|broken" --name-only --format='' \
| sort \
| uniq -c \
| sort -nr \
| head -20
}
git_commit_frequencies() {
git log --format='%ad' --date=format:'%Y-%m' \
| sort \
| uniq -c
}
git_firefighting_metric() {
git log --oneline --since="1 year ago" \
| grep -iE 'revert|hotfix|emergency|rollback'
}