-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.git_aliases
228 lines (222 loc) · 5.9 KB
/
.git_aliases
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
# From https://github.com/benhoskings/dot-files/ with personal modifications
alias ga='git add'
alias gap='ga -p'
alias gau='git add -u'
alias gaA='git add -A'
alias gae='git add -e'
alias gbr='git branch -v'
# gc() {
# git diff --cached | grep '\btap[ph]\b' >/dev/null &&
# echo "\e[0;31;29mOops, there's a #tapp or similar in that diff.\e[0m" ||
# git commit -v "$@"
# }
alias gc='git commit'
alias gc!='git commit -v'
alias gca='git commit -v -a'
alias gcA='git add -A; git commit -v'
alias gcm='git commit -v --amend'
gcmr() {
commit="${1:-HEAD}"
shift
git commit -v --amend --reset-author -c "$commit" "$@"
}
# alias gcam='gc --amend'
alias gcam='git commit -v -a --amend'
gcr() {
commit="${1:-HEAD}"
shift
git commit -v --reset-author -c "$commit" "$@"
}
gcar() {
commit="${1:-HEAD}"
shift
git commit -v -a --reset-author -c "$commit" "$@"
}
gcamr() {
commit="${1:-HEAD}"
shift
git commit -v -a --amend --reset-author -c "$commit" "$@"
}
alias gch='git cherry-pick'
alias gco='git checkout'
alias gcop='gco -p'
alias gd='git diff -M'
alias gdp='gd -p'
alias gd.='git diff -M --color-words="."'
gdbr() {
ref="$1"
shift
git diff -M "$@" $(git merge-base HEAD "$ref").."$ref"
}
alias gdc='git diff --cached -M'
alias gdc.='git diff --cached -M --color-words="."'
alias gf='git fetch'
git-new() {
[ -d "$1" ] || mkdir "$1" &&
cd "$1" &&
git init &&
touch .gitignore &&
git add .gitignore &&
git commit -m "Added .gitignore."
}
git_current_branch() {
cat "$(git rev-parse --git-dir 2>/dev/null)/HEAD" | sed -e 's/^.*refs\/heads\///'
}
alias glog='git log --date-order --pretty="format:%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset"'
alias gl='glog --graph'
glthis() {
branch="$(git_current_branch)"
gl origin/$branch...$branch
}
tlthis() {
branch="$(git_current_branch)"
tig origin/$branch...$branch
}
alias gla='gl --all --decorate'
gls() {
query="$1"
shift
glog --pickaxe-regex "-S$query" "$@"
}
alias ggl='git log --graph --all --decorate'
# alias gm='git merge --no-ff'
alias gm='git merge'
alias gmf='git merge --ff-only'
alias gmfthis='gmf origin/$(git_current_branch)'
alias gp='git push'
alias gpthis='gp origin $(git_current_branch)'
alias gpl='git pull'
alias gplod='git pull origin develop'
alias gplom='git pull origin master'
alias gr='git reset'
alias grb='git rebase -p'
alias grbthis='grb --stat origin/$(git_current_branch)'
alias grbc='git rebase --continue'
alias grba='git rebase --abort'
alias grbi='git rebase -i'
alias grh='git reset --hard'
alias grp='gr --patch'
alias grsh='git reset --soft HEAD~'
alias grv='git remote -v'
alias gbl='git blame'
#alias gs='git show'
#alias gs.='git show --color-words="."'
# alias gst='git stash'
alias gst='git stash save'
# alias gstp='git stash pop'
# alias gstpi='git stash pop --index'
alias gstl='git stash list'
# alias gsta='git stash apply'
# alias gstai='git stash apply --index'
# alias gstd='git stash drop'
gst_base() {
fn="$1" && shift;
[ ! -z "${1##*[!0-9]*}" ] && i="$1" && shift || i=0
git stash $fn stash@{"$i"} "$@"
}
gsta() {
gst_base apply "$@"
}
# TODO: improve gstaf: git stash apply force
# Could it work for the index, too?
gstaf() {
[ ! -z "${1##*[!0-9]*}" ] && index="$1" && shift || index=0
git stash show -p stash@{"$index"} | git apply
}
gstai() {
gst_base "apply --index" "$@"
}
gstp() {
gst_base pop "$@"
}
gstpi() {
gst_base "pop --index" "$@"
}
# TODO: Keep dropped stash history
gstd() {
gst_base drop "$@"
}
gsts() {
[ ! -z "${1##*[!0-9]*}" ] && index="$1" && shift || index=0
git show stash@{"$index"} "$@"
}
gstsi() { # show index of stash
[ ! -z "${1##*[!0-9]*}" ] && index="$1" && shift || index=0
git show stash@{"$index"}^2 "$@"
}
gstsu() { # show unversioned files of stash
[ ! -z "${1##*[!0-9]*}" ] && index="$1" && shift || index=0
git show stash@{"$index"}^3 "$@" 2> /dev/null || echo "No unversioned files in that stash"
}
gstu() {
git stash show -p stash@{"$1"} | git apply -R
}
alias gapp='git apply'
gdapp() {
stash="$1" && shift
gdp $stash^..$stash | gapp "$@"
}
gsta-recov() {
if [ -z "$(git status --porcelain)" ]; then
[ -n "$1" ] && gdapp $1 && gd || echo "usage: gsta-recov <commit>"
else
echo "Dirty state detected; refusing to proceed."
fi
}
gstai-recov() {
if [ -z "$(git status --porcelain)" ]; then
[ -n "$1" ] && gdapp $1 && gdapp $1^2 --index --cached && gd && gdc || echo "usage: gstai-recov <commit>"
else
echo "Dirty state detected; refusing to proceed."
fi
}
# Customizations - Josh Loya
alias gs='git status'
alias ts='tig status'
alias gcp='git cherry-pick'
alias gfu='gf upstream'
alias gfo='gf origin'
alias gsh='git show'
alias gshs='git show --stat'
alias gsh.='git show --color-words="."'
alias gshom='git show origin/master'
alias gshod='git show origin/develop'
alias tshom='tig show origin/master'
alias tshod='tig show origin/develop'
alias tsh='tig show'
alias gpdthis='gfo && gst "Temp: pop after catching up this ref" && gmfthis && gstpi' # Git pull (dirty) - stash first. TODO: Smarten gfo step.
alias gh='git help'
alias gha='git help add'
alias ghbr='git help branch'
alias ghco='git help checkout'
alias ghs='git help status'
alias ghc='git help commit'
alias ghp='git help push'
alias ghpl='git help pull'
alias ghf='git help fetch'
alias ghd='git help diff'
alias ghl='git help log'
alias ghsh='git help show'
alias ghm='git help merge'
alias ghrb='git help rebase'
alias ghst='git help stash'
alias ghr='git help reset'
alias ghcp='git help cherry-pick'
alias ghbx='git help bisect'
alias gbx='git bisect'
alias gbxs='git bisect start'
alias gbxg='git bisect good'
alias gbxb='git bisect bad'
alias gbxs='git bisect skip'
alias gbxr='git bisect reset'
alias gbxl='git bisect log'
yesterworkday()
{
[[ "1" == "$(date +%u)" ]] && echo "last friday" || echo "yesterday"
}
# alias glv='git log --since="$(yesterworkday)" --until=midnight --author="$(id -un)"' # git log verify
glv() {
day="${1:-$(yesterworkday)}" && shift
git log --since="$day" --until="11:59pm $day" --author="$(id -un)" "$@"
}