-
Notifications
You must be signed in to change notification settings - Fork 6
/
aliases
315 lines (223 loc) · 11.2 KB
/
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
; To use these aliases, you must include this file in .gitconfig
; include this stanza in your .gitconfig, where `path/to/gitin2it/aliases` is the path to this file,
; relative to the location of your .gitconfig
; [include]
; path = path/to/gitin2it/aliases
[alias]
; when was a file added
added = log --diff-filter=A --
alias = config --get-regexp ^alias\\.
aliases = config --get-regexp ^alias\\.
; show the most recent common ancestor
; see also `diverged`
ancestor = ! "gitancestor() { git merge-base --fork-point $1 $2 }; gitancestor"
; list names of contributors
; see committers, contributors
authors = ! "gitauthors() { git log --pretty='%an %ae%n%cn %ce' | sort | uniq; }; gitauthors"
; go back one commit
back = ! "gitback() { git checkout HEAD~${1:-1} ; }; gitback"
; show all branches
branches = ! "gitbranches() { git branch -a | grep ${1:-''} ; }; gitbranches"
; set the description on the branch
branch-describe = branch --edit-description
; summarize unstaged changes
changed = diff --stat
; show only changes to existing files (not new, uncommitted files, nor unstaged deletions)
changes = diff --diff-filter=M
; delete all uncommitted changes and untracked files
; alias scrub
cleanse = ! "gitcleanse() { git reset --hard; git clean -f -f -d; }; gitcleanse"
; remove all unstaged changes
clear = reset --hard
; empty git's cache
clear-cache = rm -r --cached .
; show commits that are only in this branch, and not in the other
; git commits [branch-name]
commits = ! "gitcommits() { git cherry -v ${1:-master} ; }; gitcommits"
; show unique committer usernames
; see contributors, authors
committers = ! "gitcommitters() { git log --pretty='%an %ae%n%cn %ce' | sort | uniq; }; gitcommitters"
; show files in conflict
conflicts = diff --name-only --diff-filter=U
; abbreivation for `git branch --contains`
contains = branch --contains
; copy a file wholesale from another branch, without staging it
; $ git copy <absolute-file-path> <branch>
; see `take`
copy = ! "gitcopy() { git show $2:$1 > $1 ; }; gitcopy"
; show unique contributor usernames
; see authors, committers
contributors = ! "gitcontributors() { git log --pretty='%an %ae%n%cn %ce' | sort | uniq; }; gitcontributors"
; show just the name of the current branch
current = rev-parse --abbrev-ref HEAD
; delete a branch on local and remote
; `git cut BRANCH-NAME [REMOTE-NAME]`
cut = ! "gitcut() { git branch -d $1; git push ${2:-origin} --delete $1; }; gitcut"
; alias for checkout -p
; git discard [filename]
discard = ! "gitdiscard() { git checkout -p ${1}; }; gitdiscard"
; show the most recent common ancestor
; see also `ancestor`
diverged = ! "gitdiverged() { git merge-base --fork-point $1 $2 }; git diverged"
; commit file deletions not done by `git rm`.
; TODO: add specify filename feature
delete = ! "gitdelete() { git diff --diff-filter=D --name-only | xargs git rm; }; gitdelete"
; show the log of files deleted in this branch
deleted = ! "gitdeleted() { git log --diff-filter=D --summary; }; gitdeleted"
; set the description on the branch
describe-branch = branch --edit-description
; show the description of the current/specified branch
description = ! "gitdescription() { git config branch.${1:-$(git rev-parse --abbrev-ref HEAD)}.description ; }; gitdescription"
; syntax sugar and QoL for `git diff --stat`
; use `tput` to apply the approprate column size in a `diff --stat`
; $ git diff-stat [branch]
diff-stat = ! "gitdiffstat() { git diff --stat=$(tput cols) $1 ; }; gitdiffstat"
; find a string
; https://stackoverflow.com/a/13878026
find = ! "gitfind() { git rev-list --all | xargs git grep $1 ; }; gitfind"
; find a file (or partial filename match) anywhere in the repo
; https://stackoverflow.com/a/37212743/151841
; $ git find-file PATTERN
find-file = ! "gitfindfile() { for branch in $(git for-each-ref --format=\"%(refname)\" refs/heads); do if git ls-tree -r --name-only $branch | grep \"$1\" > /dev/null; then echo \"${branch}:\"; git ls-tree -r --name-only $branch | nl -bn -w3 | grep \"$1\"; fi; done; }; gitfindfile"
; if you've added a tracked file to the .gitignore, it will still persist. This removes it.
forget = rm --cached
; show what files are ignored
ignored = ls-files --others --exclude-standard --ignored
; set the current repo to ignore filemode
ignore-filemode = config core.fileMode false
; in which commit was a file introduced
; see `added`
introduced = log --diff-filter=A --
; commit only modifications, don't commit additions or deletions
keep = commit -a
; keep both
; https://stackoverflow.com/a/55187779/151841
keep-both = ! "gitkeepboth() { grep -v -e'^<<<<<<<' -e'^>>>>>>>' -e'=======' $1 > $1.tmp; mv $1.tmp $1; git add $1; }; gitkeepboth"
; show the latest commits
; alias `newest`
latest = for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
; show local branches
local = branch
locals = branch
; show the standard log, but only commits that are tagged
log-tags = ! "gittaglog() { git log --date-order --date=format:'%Y-%m-%d %H:%M:%S' --format='%C(yellow)%cd%Creset %h \"%d %s\" %Cred%cn %Cgreen(%cr)' | grep tag ; }; gittaglog"
; use `tput` to apply the approprate column size in a `log --stat`
log-stat = ! "gitlogstat() { git log --stat=$(tput cols) $1 ; }; gitlogstat"
; show merged branches
merged = branch --merge
; show diff(s) of modified files only (no untracked or deleted files)
modified = diff --diff-filter=M
; show only new (unstaged) files
new = ls-files --others --exclude-standard
; check out the next commit going towards a branch head
; $ git checkout next master
; https://stackoverflow.com/a/14200660/151841
next = ! "gitnext() { git checkout $( git rev-list --topo-order HEAD.."$1" | tail -n 1 ) ; }; gitnext"
; show local branches not tracking a remote
non-tracking = ! "gitnonntracking() { git branch -vv | cut -c 3- | awk '$3 !~/\\[/ { print $1 }' ; }; gitnonntracking"
; "obituary" -- in which commit was a file deleted
; git obit [filename]
; "obituaries"-- show log only of file delestions
obits = !"gitobits() { git log --diff-filter=D --summary; }; gitobits"
; show the log in oneline format
oneline = log --oneline
; show the state of the current git repo
state = ! "git rev-parse --show-toplevel; git remote -v; git branch; git status; git rev-parse HEAD;"
; `cherry-pick` is simply too much typing
pick = cherry-pick
; show the root directory of the repository
pwd = rev-parse --show-toplevel;
; show only remote branches
remote-branches = branch -r
; show all remote repos
remotes = remote -v
; restore a file whose deletion has been committed
; $ git restore FILENAME
restore = !git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
revive = !git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
resurrect = !git checkout $(git rev-list -n 1 HEAD -- "$1")^ -- "$1"
; delete a branch locally and remotely
; $ git remove BRANCHNAME [remote]
remove = ! "gitremove() { git branch -D $1 && git push ${2:-origin} --delete $1 ; }; gitremove"
; rename a branch
; $ git rename OLDNAME NEWNAME [remote]
; https://stackoverflow.com/a/30590238/151841
rename = ! "gitrename() { git branch -m $1 $2 && git push ${3:-origin} --delete $1 && git push ${3:-origin} $2 && git push ${3:-origin} -u $2; }; gitrename"
; commit with the default commit message
resolve = commit --file .git/MERGE_MSG
; show if branches are ahead or behind of remote
schedule = for-each-ref --format="%(refname:short) %(upstream:track)" refs/heads
; delete all uncommitted changes and untracked files
; alias cleanse
scrub = ! "gitscrub() { git reset --hard; git clean -f -f -d; }; gitscrub"
; search the repo for a string
; https://stackoverflow.com/a/13878026/151841
; https://stackoverflow.com/a/49243541/151841
search = ! "gitsearch() { git rev-list --all | xargs git grep $1; }; gitsearch"
; set the upstream repo {default `origin`} (useful when git tells you a long --set-upstream command)
; git set-upstream [remote|'origin']
set-upstream = ! "gitsetupstream() { BRANCH=$(git rev-parse --abbrev-ref HEAD); git push ${1:-origin} $BRANCH; git branch --set-upstream-to=${1:-origin}/$BRANCH $BRANCH; }; gitsetupstream"
; show the filesystem size of the tracked objects in the repo
size = count-objects -vH
short-stat = status --short
; keep a file from changing, see `unskip`, `skipped`
skip = update-index --skip-worktree
; Show which worktrees are skipped. See `skip`, `unskip`
skipped = ! "gitskipped() { git ls-files -v | grep ^[sS] ; }; gitskipped"
; do a squash commit
squash = merge --squash
; stash all files, including untracked ones
; "How do I _stash untracked_ files?"
stash-untracked = stash --untracked --
; stash unstaged changes only (leave staged changes alone)
stash-unstaged = stash --keep-index -u
; list current stashes
stashes = stash list
; show files that are staged (added but not committed)
staged = diff --cached
; stop whatever stoppable process git is in the middle of (merge, bisect)
stop = ! "gitstop() { git bisect reset; git merge --abort; }; gitstop"
; show all tags
; I made this is a bash function so that you can't accidentally set a tag with this
tags = ! "gittags() { git tag; }; gittags"
; copy a file wholesale form another branch, and stage it
; see `copy`
take = ! "gittake() { git checkout $1 $2 ; }; gittake"
; show just the name of the current branch
this = rev-parse --abbrev-ref HEAD
; show what files are being tracked
tracked = ! "gittracked() { git ls-tree -r $(git rev-parse --abbrev-ref HEAD) --name-only ; }; gittracked"
; show what remote(s) the current branch is tracking
tracking = rev-parse --abbrev-ref --symbolic-full-name @{u}
; restore deleted files if changes aren't staged
undelete = ! "gitundelete() { git status | grep 'deleted' | awk '{print $2}' | xargs git checkout -- ; }; gitundelete"
; show what files would be committed
uncommitted = ls-files --others --exclude-standard
; remove changes from staging area and reintroduce them as changes/diffs
uncommit = reset --soft HEAD^
; remove the lock file
unlock = ! "gitunlock() { rm -f ./.git/index.lock ; }; gitunlock"
; show branches unmerged into specified branch
; git unmerged [BRANCH|'master']
unmerged = ! "gitunmerged() { git branch --no-merged ${1:-master}; }; gitunmerged"
; tell git to start noticing changes to a file again. See `skip`, `skipped`
unskip = update-index --no-skip-worktree
; unstaged staged changes
unstage = reset
; show what files are not tracked
untracked = ls-files --others --exclude-standard --ignored
; delete new, untracked, uncommitted files
unwelcome = clean -f -d
; show all local branches with commits not pushed
unpushed = log --branches --not --remotes --no-walk --decorate
; show what files are tracked in the repos
versioned = ls-tree -r master --name-only
; add (`git add`) unstaged files
welcome = ! "gitaddnew() { git ls-files --others --exclude-standard | xargs git add ; }; gitaddnew"
; show username and email
whoami = ! "gitwhoami() { git config user.name; git config user.email; }; gitwhoami"
; show branches out of date (don't have the commits from) with a branch
without = ! "gitwithout() { git branch --no-contains ${1:-master}; }; gitwithout"
; word diff
word-diff = diff --word-diff
wd = diff --word-diff