-
Notifications
You must be signed in to change notification settings - Fork 0
/
githelpers
194 lines (164 loc) · 4.37 KB
/
githelpers
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
set -e
wip() {
options=$*
git add -A
git commit --no-verify -m "wip $options"
}
unwip() {
if [ "`git log --format=%B -n 1 HEAD`" = "wip" ]; then
git reset --soft HEAD~1;
git reset HEAD;
fi;
}
uncommit() {
local id=$(git rev-parse --short HEAD)
local title=$(git log --format="%s" -1)
if (which pbcopy &>/dev/null); then
local message=$(git log --format="%B" -1)
echo "${message}" | pbcopy
fi
git reset --soft HEAD~ && echo "Reset commit \"${title}\" (was ${id})."
}
diff_branch() {
if [[ $1 == *"--"* ]]; then
branch=$(git rev-parse --abbrev-ref HEAD)
options=$*
else
branch=$1
options=${@:2}
fi
git diff $options $(git merge-base --fork-point origin/$DEFAULT_BRANCH $branch)..$branch
}
log() {
options=$*
git --no-pager log --color $options --decorate | less --pattern '^commit'
}
log_patch() {
options=$*
git --no-pager log --color --patch $options --decorate | less --pattern '^commit'
}
log_patch_reverse_branch() {
options=$*
start=$(git merge-base --fork-point origin/$DEFAULT_BRANCH)
git --no-pager log $start..HEAD --patch --reverse --color $options | less --pattern '^commit'
}
search() {
query=$*
git --no-pager log --color=always -S "${query}" --patch | less --pattern "${query}"
}
merge_branch_origin_to_master() {
branch=$(git rev-parse --abbrev-ref HEAD)
git checkout master
git merge --no-ff origin/$branch
}
selecta_branch() {
git branch -a |
cut -c 3- |
sed 's:remotes/origin/::' |
grep -v HEAD |
sort -u |
selecta |
xargs git checkout
}
selecta_recent_branch() {
bash << EOS
cat <(git reflog -n 100 | grep -E 'checkout:|Branch: renamed' | grep -Eo "\S+$") \
<(git branch | cut -c 3-) \
| sed 's:refs/heads/::' \
| awk '!x[\$0]++' \
| grep -v $(git rev-parse --abbrev-ref HEAD) \
| selecta \
| xargs git checkout
EOS
}
tail_origin_log() {
log_options=$1
branch='origin/master'
interval=360
while true; do
clear
git --no-pager log --color --graph --decorate $log_options $branch -20 \
| head -n $(expr $(tput lines) - 1)
sleep $interval
git fetch
done
}
pretty_log() {
git log --graph --pretty=format:"%C(yellow)%h%C(red)%d%C(reset) %s (%C(green)%an%C(reset), %C(blue)%ar%C(reset))"
}
new() {
[ -z $1 ] && >&2 echo "fatal: new directory path required" && exit 1
mkdir -p "$1"
git_dir="./${1}/.git"
git init "$1" \
&& git --git-dir=$git_dir commit --allow-empty -m "Initial commit" \
&& git --git-dir=$git_dir tag root
[ $TMUX ] && tmux send-keys "cd ${1}" C-m
}
blame_files() {
arg_files="$*"
for file in $(echo $arg_files); do
blame_file $file
done | column -t -s "•" | less
}
blame_file() {
file=$1
git --no-pager log --color=always --format="%ai•${file}•%C(blue)%an%C(reset)•%C(yellow)%h%C(reset) %s" -1 $file
}
jcoglan_graph() {
options="$*"
git --no-pager log --color=always $options --graph \
--format="%C(yellow)%h%C(green)%d %C(blue)(%an, %ar) %C(reset)%n%w(72)%s%n" \
| less --pattern "([0-9]|[a-f]){7,}"
}
rebase_upstream() {
options="$*"
upstream=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
git rebase $options $upstream
}
upstream() {
git rev-parse --abbrev-ref --symbolic-full-name @{u}
}
log_all() {
git log --oneline --graph --decorate --all $(git reflog show --format="%h" stash)
}
delete_local_merged_branches() {
git branch --merged "${DEFAULT_BRANCH:-master}" |
grep -v "*" |
grep -v master |
grep -v staging |
xargs -n 1 git branch --delete
}
delete_remote_merged_branches() {
branches=$(
git branch -a --merged origin/"${DEFAULT_BRANCH:-master}" \
| grep --color=never remotes \
| grep -v HEAD \
| grep -v staging \
| grep -v developement \
| grep -v master \
| sed "s:remotes/origin/::g"
)
echo $branches
printf "Delete branches? (y/n) "
if (read -q); then
echo
echo $branches | xargs -L 1 git push origin --delete
else
exit 1
fi
}
truncating_log() {
local options="$*"
local hash="%C(yellow)%h%C(reset)"
local author_date="%C(red)%ad%C(reset)"
local author_name="%<(7,trunc)%C(blue)%an%C(reset)"
local message="%<(50,mtrunc)%s"
local decorations="%C(green)%d%C(reset)"
git --no-pager log --color=always $options \
--graph \
--date=iso \
--pretty="$hash $author_date $author_name $message $decorations" \
| less
}