-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitalias.txt
1458 lines (1222 loc) · 56.2 KB
/
gitalias.txt
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- mode: gitconfig; -*-
# vim: set filetype=gitconfig:
##
# GitAlias.com file of many git alias items, including shortcuts, helpers, workflows, etc.
#
#
# ## Usage
#
# Typical usage for a typical user:
#
# * Save this file as a dot file in your home directory: `~/.gitalias.txt`
#
# * Edit your git config dot file in your home directory such as `~/.gitconfig`
#
# * Include the path to this file.
#
# Example file `~/.gitconfig` with an entry to include the file `~/.gitalias.txt`:
#
# [include]
# path = gitalias.txt
#
#
# ## Usage for older git versions
#
# If you use an older version of git that does not have git config "include" capability,
# or if you prefer more control, then you can simply copy/paste anything you like from
# this file to your own git config file.
#
#
# ## Customization
#
# If you want to use this file, and also want to change some of the items,
# then one way is to use your git config file to include this gitalias file,
# and also define your own alias items; a later alias takes precedence.
#
# Example file `~/.gitconfig` item to include the file `~/.gitalias.txt`:
#
# [include]
# path = ~/.gitconfig.d/gitalias.txt
# [alias]
# l = log --graph --oneline
#
#
# ## Links
#
# * [GitAlias.com website](http://gitlias.com)
# * [GitAlias GitHub](https://github.com/gitalias)
# * [Git Basics - Git Aliases](https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases)
# * [Git Basics - Tips and Tricks](https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks)
#
# ## Tracking
#
# * Package: gitalias
# * Version: 23.2.0
# * Created: 2016-06-17T00:00:00Z
# * Updated: 2020-07-10T01:08:58Z
# * License: GPL-2.0-only
# * Contact: Joel Parker Henderson ([email protected])
##
[alias]
##
# One letter alias for our most frequent commands.
#
# Guidelines: these aliases do not use options, because we want
# these aliases to be easy to compose and use in many ways.
##
a = add
b = branch
c = commit
d = diff
f = fetch
g = grep
l = log
m = merge
o = checkout
p = pull
r = remote
s = status
w = whatchanged
##
# Short aliases for our frequent commands.
#
# Guidelines:
#
# * Generally speaking, the alias should be in the same
# order as the command name followed by its options.
#
# * Right: fb = foo --bar
# * Wrong: bf = foo --bar
##
### add ###
# add all
aa = add --all
# add by patch - looks at each change, and asks if we want to put it in the repo.
ap = add --patch
# add just the files that are updated.
au = add --update
### branch ###
# branch description
bd = !"git config branch.$(git rev-parse --abbrev-ref HEAD 2>/dev/null).description"
# bra nch - edit the description
be = branch --edit-description
# branch and only list branches whose tips are reachable from the specified commit (HEAD if not specified).
bm = branch --merged
# branch and only list branches whose tips are not reachable from the specified commit (HEAD if not specified).
bnm = branch --no-merged
### commit ###
# commit - amend the tip of the current branch rather than creating a new commit.
ca = commit --amend
# commit - amend the tip of the current branch, and edit the message.
cam = commit --amend --message
# commit - amend the tip of the current branch, and do not edit the message.
cane = commit --amend --no-edit
# commit interactive
ci = commit --interactive
# commit with a message
cm = commit --message
### checkout ###
# checkout - update the working tree to match a branch or paths. [same as "o" for "out"]
co = checkout
con = checkout --no-guess
### cherry-pick ###
# cherry-pick - apply the changes introduced by some existing commits; useful for moving small chunks of code between branches.
cp = cherry-pick
# cherry-pick - abort the picking process
cpa = cherry-pick --abort
# cherry-pick - continue the picking process
cpc = cherry-pick --continue
# cherry-pick without making a commit, and when when recording the commit, append a line that says "(cherry picked from commit ...)"
cp-nx = cherry-pick --no-commit -x
### diff ###
# diff - show changes not yet staged
dc = diff --cached
# diff - show changes about to be commited
ds = diff --staged
# diff - show changes but by word, not line
dw = diff --word-diff
# diff deep - show changes with our preferred options. Also aliased as `diff-deep`.
dd = diff --check --dirstat --find-copies --find-renames --histogram --color
### clean ###
# clean everything to be pristine
cleanest = clean -ffdx
### grep ###
# grep i.e. search for text
g = grep
# grep - show line number
gl = grep --line-number
# grep group - search with our preferred options. Also aliased as `grep-group`.
gg = grep --break --heading --line-number --color
### log ###
# log with a text-based graphical representation of the commit history.
lg = log --graph
# log with one line per item.
lo = log --oneline
# log with patch generation.
lp = log --patch
# log with first parent, useful for team branch that only accepts pull requests
lfp = log --first-parent
# log with items appearing in topological order, i.e. descendant commits are shown before their parents.
lt = log --topo-order
# log like - we like this summarization our key performance indicators. Also aliased as `log-like`.
ll = log --graph --topo-order --date=short --abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
# log like long - we like this summarization our key performance indicators. Also aliased as `log-like-long`.
lll = log --graph --topo-order --date=iso8601-strict --no-abbrev-commit --abbrev=40 --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn <%ce>]%Creset %Cblue%G?%Creset'
## ls-files ##
# ls-files - show information about files in the index and the working tree; like Unix "ls" command.
ls = ls-files
# ls-ignored - list files that git has ignored.
ls-ignored = ls-files --others --i --exclude-standard
### merge ###
# merge but without autocommit, and with a commit even if the merge resolved as a fast-forward.
me = merge --no-commit --no-ff
### pull ###
# pull if a merge can be resolved as a fast-forward, otherwise fail.
pf = pull --ff-only
# pull with rebase - to provide a cleaner, linear, bisectable history.
#
# To automatically do "pull --rebase" everywhere:
#
# git config --global pull.rebase true
#
# To automatically do "pull --rebase" for any branch based on master:
#
# git config branch.master.rebase true
#
# To automatically do "pull --rebase" for any newly-created branches:
#
# git config --global branch.autosetuprebase always
#
# To integrate changes between branches, you can merge or rebase.
#
# When we use "git pull", git does a fetch then a merge.
# If we've made changes locally and someone else has pushed changes
# to our git host then git will automatically merge these together
# and create a merge commit that looks like this in the history:
#
# 12345678 - Merge branch 'foo' of bar into master
#
# When we use "git pull --rebase", git does a fetch then a rebase.
# A rebase resets the HEAD of your local branch to be the same as
# the remote HEAD, then replays your local commits back into repo.
# This means you don't get any noisy merge messages in your history.
# This gives us a linear history, and also helps with git bisect.
#
pr = pull --rebase
# pp - pull with rebase preserve of merge commits
#
# See https://stackoverflow.com/questions/21364636/git-pull-rebase-preserve-merges
#
# You should only rebase if you know (in a sort of general sense)
# what you are doing, and if you do know what you are doing, then you
# would probably prefer a merge-preserving rebase as a general rule.
#
# Although by the time you've decided that rebasing is a good idea,
# you will probably find that a history that has its own embedded
# branch-and-merge-points is not necessarily the correct "final
# rewritten history".
#
# That is, if it's appropriate to do a rebase at all, it's at least fairly
# likely that the history to be rebased is itself linear, so that the
# preserve-vs-flatten question is moot anyway.
#
# See https://stackoverflow.com/questions/38269092/is-it-possible-to-put-preserve-merges-in-the-gitconfig
#
# While preserving merges is probably generally superior, in at least a
# few ways, to discarding them when rebasing, the fact is that rebase
# cannot preserve them. The only thing it can do, once some commits
# have been copied to new commits, is re-perform them. This can have new
# and/or different merge conflicts, vs the last time the merge was done.
# You should also pay close attention to the restrictions on merge
# preservation in the git rebase documentation.
#
# Without getting into a lot of detail, it always seems to me that most
# commit graph subsets that "should be" rebased, rarely have any
# internal merges. If such a graph subset has a single final merge, you
# can simply strip away that merge (with git reset) before rebasing,
# and re-do that single merge manually at the end. (In fact, git rebase
# normally drops merge commits entirely, so you don't have to run the git
# reset itself in some cases. The one where you do have to run it is when
# the merge is into the branch onto which you intend to rebase. This is
# where git pull actually does the right thing when it uses
# `git rebase -p`, except that it fails to check for, and warn about,
# internal merges, which are sort of warning signs that rebasing might
# not be a good idea.
#
pp = pull --rebase=preserve
### rebase ###
# rebase - forward-port local commits to the updated upstream head.
rb = rebase
# rebase abort - cancel the rebasing process
rba = rebase --abort
# rebase - continue the rebasing process after resolving a conflict manually and updating the index with the resolution.
rbc = rebase --continue
# rebase - restart the rebasing process by skipping the current patch.
rbs = rebase --skip
# rbi - rebase interactive on our unpushed commits.
#
# Before we push our local changes, we may want to do some cleanup,
# to improve our commit messages or squash related commits together.
#
# Let's say I've pushed two commits that are related to a new feature and
# I have another where I made a spelling mistake in the commit message.
# When I run "git rbi" I get dropped into my editor with this:
#
# pick 7f06d36 foo
# pick ad544d0 goo
# pick de3083a hoo
#
# Let's say I want to squash the "foo" and "goo" commits together,
# and also change "hoo" to say "whatever". To do these, I change "pick"
# to say "s" for squash; this tells git to squash the two together;
# I also edit "hoo" to rename it to "whatever". I make the file look like:
#
# pick 7f06d36 foo
# s ad544d0 goo
# r de3083a whatever
#
# This gives me two new commit messages to edit, which I update.
# Now when I push the remote repo host receives two commits
#
# 3400455 - foo
# 5dae0a0 - whatever
#
rbi = rebase --interactive @{upstream}
# See https://blog.filippo.io/git-fixup-amending-an-older-commit/
# This is a slightly modified version
fixup = "!f() { TARGET=$(git rev-parse \"$1\"); git commit --fixup=$TARGET && GIT_EDITOR=true git rebase --interactive --autosquash $TARGET~; }; f"
### reflog ###
# reflog - reference log that manages when tips of branches are updated.
rl = reflog
### remote ###
# remote - manage set of tracked repositories [same as "r"].
rr = remote
# remote show - gives some information about the remote <name>.
rrs = remote show
# remote update - fetch updates for a named set of remotes in the repository as defined by remotes.
rru = remote update
# remote prune - deletes all stale remote-tracking branches under <name>.
rrp = remote prune
incoming = !git remote update --prune; git log ..@{upstream}
outgoing = log @{upstream}..
# Push to all remotes
push-to-all-remotes = !git remote | xargs -I% -n1 git push %
### revert ###
# revert - undo the changes from some existing commits
rv = revert
# revert without autocommit; useful when you're reverting more than one commits' effect to your index in a row.
rvnc = revert --no-commit
### show-branch ###
# show-branch - print a list of branches and their commits.
sb = show-branch
### submodule ###
# submodule - enables foreign repositories to be embedded within a dedicated subdirectory of the source tree.
sm = submodule
# submodule init
smi = submodule init
# submodule add
sma = submodule add
# submodule sync
sms = submodule sync
# submodule update
smu = submodule update
# submodule update with initialize
smui = submodule update --init
# submodule update with initialize and recursive; this is useful to bring a submodule fully up to date.
smuir = submodule update --init --recursive
### status ###
# status with short format instead of full details
ss = status --short
# status with short format and showing branch and tracking info.
ssb = status --short --branch
### ALIAS MANAGEMENT ###
# Show our defined alias list
aliases = "!git config --get-regexp '^alias\\.' | cut -c 7- | sed 's/ / = /'"
add-alias = "!f() { [ $# = 3 ] && git config $1 alias.\"$2\" \"$3\" && return 0 || echo \"Usage: git add-(local|global)-alias <new alias> <original command>\" >&2 && return 1; }; f"
add-global-alias = "!git add-alias --global"
add-local-alias = "!git add-alias --local"
# Rename an alias
rename-alias = "!f() { [ $# = 3 ] && [ $2 != $3 ] && [ ! -z \"$(git config $1 --get alias.$2)\" ] && [ -z \"$(git config $1 --get alias.$3)\" ] && git config $1 alias.$3 \"$(git config $1 --get alias.$2)\" && git config $1 --unset alias.$2 && return 0 || echo \"Usage: git rename-(local|global)-alias <alias existing name> <new alias name>\nThe alias you are going to rename must exist and new name must not exist.\" >&2 && return 1; };f"
rename-global-alias = "!git rename-alias --global"
rename-local-alias = "!git rename-alias --local"
# Last tag in the current branch
lasttag = describe --tags --abbrev=0
# Latest annotated tag in all branches
lasttagged = !git describe --tags `git rev-list --tags --max-count=1`
# From https://gist.github.com/492227
head = log -n1
heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
lost = !"git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub(\"SHA1: \", \"\"); print}'"
### diff-* ###
diff-all = !"for name in $(git diff --name-only $1); do git difftool $1 $name & done"
diff-changes = diff --name-status -r
diff-stat = diff --stat --ignore-space-change -r
diff-staged = diff --cached
# Diff using our preferred options. A.k.a. `dd`.
diff-deep = diff --check --dirstat --find-copies --find-renames --histogram --color
### grep-* ###
# Find text in any commit ever.
grep-all = !"f() { git rev-list --all | xargs git grep \"$@\"; }; f"
# Find text and group the output lines. A.k.a. `gg`.
grep-group = grep --break --heading --line-number --color
# grep with ack-like formatting
grep-ack = \
-c color.grep.linenumber=\"bold yellow\" \
-c color.grep.filename=\"bold green\" \
-c color.grep.match=\"reverse yellow\" \
grep --break --heading --line-number
### init ###
# initalize a repo and immediate add an empty commit, which makes rebase easier.
init-empty = !"f() { git init && git commit --allow-empty --allow-empty-message --message ''; }; f"
### merge-* ###
# Given a merge commit, find the span of commits that exist(ed).
# Not so useful in itself, but used by other aliases.
# Thanks to Rob Miller for the merge-span-* aliaes.
merge-span = !"f() { echo $(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f1)$1$(git log -1 $2 --merges --pretty=format:%P | cut -d' ' -f2); }; f"
# Find the commits that were introduced by a merge
merge-span-log = "!git log `git merge-span .. $1`"
# Show the changes that were introduced by a merge
merge-span-diff = !"git diff `git merge-span ... $1`"
# Show the changes that were introduced by a merge, in your difftool
merge-span-difftool = !"git difftool `git merge-span ... $1`"
# Interactively rebase all the commits on the current branch
rebase-branch = !"git rebase --interactive `git merge-base master HEAD`"
# Sort by date for branches; can be useful for spring cleaning
refs-by-date = for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short)'
# Find all objects that aren't referenced by any other object (orphans).
# To help an orphan, we create a new branch with the orphan's commit hash,
# then merge it into our current branch:
#
# git branch foo <commit>
# git merge foo
#
orphans = fsck --full
# List all blobs by size in bytes.
# By [CodeGnome](http://www.codegnome.com/)
rev-list-all-objects-by-size = !"git rev-list --all --objects | awk '{print $1}'| git cat-file --batch-check | fgrep blob | sort -k3nr"
# List all objects by size in bytes and file name.
# By [raphinesse](https://stackoverflow.com/users/380229/raphinesse)
rev-list-all-objects-by-size-and-name = !"git rev-list --all --objects | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | awk '/^blob/ {print substr($0,6)}' | sort --numeric-sort --key=2"
### LOG ALIASES ###
# Show log of changes, most recent first
log-changes = log --oneline --reverse
# Show log of new commits after you fetched, with stats, excluding merges
log-fresh = log ORIG_HEAD.. --stat --no-merges
# Show log in our preferred format for our key performance indicators. A.k.a. `ll`.
log-like = log --graph --topo-order --date=short --abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn]%Creset %Cblue%G?%Creset'
# Show log in our preferred format for our key performance indicators, with long items. A.k.a. `lll`.
log-like-long = log --graph --topo-order --date=iso8601-strict --no-abbrev-commit --decorate --all --boundary --pretty=format:'%Cgreen%ad %Cred%h%Creset -%C(yellow)%d%Creset %s %Cblue[%cn <%ce>]%Creset %Cblue%G?%Creset'
# Show log with dates in our local timezone
log-local = log --date=local
# Show the log for my own commits by my own user email
log-my = !git log --author $(git config user.email)
# Show log as a graph
log-graph = log --graph --all --oneline --decorate
# Show the date of the earliest commit, in strict ISO 8601 format
log-first-date = !"git log --date-order --format=%cI | tail -1"
# Show the date of the latest commit, in strict ISO 8601 format
log-latest-date = log -1 --date-order --format=%cI
# Show the log of the recent hour, day, week, month, year
log-hour = log --since=1-hour-ago
log-day = log --since=1-day-ago
log-week = log --since=1-week-ago
log-month = log --since=1-month-ago
log-year = log --since=1-year-ago
# Show the log of my own recent hour, day, week, month, year
log-my-hour = log --author $(git config user.email) --since=1-hour-ago
log-my-day = log --author $(git config user.email) --since=1-day-ago
log-my-week = log --author $(git config user.email) --since=1-week-ago
log-my-month = log --author $(git config user.email) --since=1-month-ago
log-my-year = log --author $(git config user.email) --since=1-year-ago
# Show a specific format string and its number of log entries
log-of-format-and-count = "!f() { format=\"$1\"; shift; git log $@ --format=oneline --format="$format" | awk '{a[$0]++}END{for(i in a){print i, a[i], int((a[i]/NR)*100) \"%\"}}' | sort; }; f"
log-of-count-and-format = "!f() { format=\"$1\"; shift; git log $@ --format=oneline --format="$format" | awk '{a[$0]++}END{for(i in a){print a[i], int((a[i]/NR)*100) \"%\", i}}' | sort -nr; }; f"
# Show the number of log entries by a specific format string and date format string
log-of-format-and-count-with-date = "!f() { format=\"$1\"; shift; date_format=\"$1\"; shift; git log $@ --format=oneline --format=\"$format\" --date=format:\"$date_format\" | awk '{a[$0]++}END{for(i in a){print i, a[i], int((a[i]/NR)*100) \"%\"}}' | sort -r; }; f"
log-of-count-and-format-with-date = "!f() { format=\"$1\"; shift; date_format=\"$1\"; shift; git log $@ --format=oneline --format=\"$format\" --date=format:\"$date_format\" | awk '{a[$0]++}END{for(i in a){print a[i], int((a[i]/NR)*100) \"%\", i}}' | sort -nr; }; f"
# Show the number of log items by email
log-of-email-and-count = "!f() { git log-of-format-and-count \"%aE\" $@; }; f"
log-of-count-and-email = "!f() { git log-of-count-and-format \"%aE\" $@; }; f"
# Show the number of log items by hour
log-of-hour-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m-%dT%H\" $@ ; }; f"
log-of-count-and-hour = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m-%dT%H\" $@ ; }; f"
# Show the number of log items by day
log-of-day-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m-%d\" $@ ; }; f"
log-of-count-and-day = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m-%d\" $@ ; }; f"
# Show the number of log items by week
log-of-week-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y#%V\" $@; }; f"
log-of-count-and-week = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y#%V\" $@; }; f"
# Show the number of log items by month
log-of-month-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y-%m\" $@ ; }; f"
log-of-count-and-month = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y-%m\" $@ ; }; f"
# Show the number of log items by year
log-of-year-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%Y\" $@ ; }; f"
log-of-count-and-year = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%Y\" $@ ; }; f"
# Show the number of log items by hour of day
log-of-hour-of-day-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%H\" $@; }; f"
log-of-count-and-hour-of-day = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%H\" $@; }; f"
# Show the number of log items by day of week
log-of-day-of-week-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%u\" $@; }; f"
log-of-count-and-day-of-week = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%u\" $@; }; f"
# Show the number of log items by week of year
log-of-week-of-year-and-count = "!f() { git log-of-format-and-count-with-date \"%ad\" \"%V\" $@; }; f"
log-of-count-and-week-of-year = "!f() { git log-of-count-and-format-with-date \"%ad\" \"%V\" $@; }; f"
# TODO
log-refs = log --all --graph --decorate --oneline --simplify-by-decoration --no-merges
log-timeline = log --format='%h %an %ar - %s'
log-local = log --oneline origin..HEAD
log-fetched = log --oneline HEAD..origin/master
# chart: show a summary chart of activity per author.
#
# Example:
#
# $ git chart
# ..X..........X...2..12 [email protected]
# ....2..2..13.......... [email protected]
# 2.....1....11......... [email protected]
# ..1............1..1... [email protected]
# ....1.......1.3.3.22.2 [email protected]
#
# The chart rows are the authors.
# TODO: sort the rows meaningfully,
# such as alphabetically, or by count.
#
# The chart columns are the days.
# The chart column prints one character per day.
#
# * For 1-9 commits, show the number.
# * For 10 or more commits, show "X" as a visual indicator.
# * For no commits, show "." as a visual placeholder.
#
# The chart timeline adjusts the date range automatically:
#
# * The timeline starts with the date of the earliest commit.
# * The timeline stops with the date of the latest commit.
# * The intent is to show the most relevant information.
#
# The chart default is to look at the past 6 weeks;
# this gives a good balance of recency and speed
# for a team that's currently working on a repo,
# and also gives a good balance of fitting within
# one terminal window 80 character width.
#
# You can adjust how far back the chart looks,
# by providing your own `--since` parameter.
# For example if you want to chart an older repo,
# that does not have any recent commits, then you
# you must provide a longer `--since` parameter.
#
chart = "!f() { \
git log \
--format=oneline \
--format=\"%aE %at\" \
--since=6-weeks-ago \
$* | \
awk ' \
function time_to_slot(t) { return strftime(\"%Y-%m-%d\", t, true) } \
function count_to_char(i) { return (i > 0) ? ((i < 10) ? i : \"X\") : \".\" } \
BEGIN { \
time_min = systime(); time_max = 0; \
SECONDS_PER_DAY=86400; \
} \
{ \
item = $1; \
time = 0 + $2; \
if (time > time_max){ time_max = time } else if (time < time_min){ time_min = time }; \
slot = time_to_slot(time); \
items[item]++; \
slots[slot]++; \
views[item, slot]++; \
} \
END{ \
printf(\"Chart time range %s to %s.\\n\", time_to_slot(time_min), time_to_slot(time_max)); \
time_max_add = time_max += SECONDS_PER_DAY; \
for(item in items){ \
row = \"\"; \
for(time = time_min; time < time_max_add; time += SECONDS_PER_DAY) { \
slot = time_to_slot(time); \
count = views[item, slot]; \
row = row count_to_char(count); \
} \
print row, item; \
} \
}'; \
}; f"
# churn: show log of files that have many changes
#
# * Written by (Corey Haines)[http://coreyhaines.com/]
# * Scriptified by Gary Bernhardt
# * Obtained from https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn
# * Edited for GitAlias.com repo by Joel Parker Henderson
# * Comments by Mislav http://mislav.uniqpath.com/2014/02/hidden-documentation/
#
# Show churn for whole repo:
#
# $ git churn
#
# Show churn for specific directories:
#
# $ git churn app lib
#
# Show churn for a time range:
#
# $ git churn --since=1-month-ago
#
# These are all standard arguments to `git log`.
#
# It's possible to get valuable insight from history of a project not only
# by viewing individual commits, but by analyzing sets of changes as a whole.
# For instance, `git churn` compiles stats about which files change the most.
#
# For example, to see where work on an app was focused on in the past month:
#
# $ git churn --since=1-month-ago app/ | tail
#
# This can also highlight potential problems with technical debt in a project.
# A specific file changing too often is generally a red flag, since it probably
# means the file either needed to be frequently fixed for bugs, or the file
# holds too much responsibility and should be split into smaller units.
#
# Similar methods of history analysis can be employed to see which people were
# responsible recently for development of a certain part of the codebase.
#
# For instance, to see who contributed most to the API part of an application:
#
# $ git log --format='%an' --since=1-month-ago app/controllers/api/ | \
# sort | uniq -c | sort -rn | head
#
# 109 Alice Anderson
# 13 Bob Brown
# 7 Carol Clark
#
churn = !"f() { git log --all --find-copies --find-renames --name-only --format='format:' \"$@\" | awk 'NF{a[$0]++}END{for(i in a){print a[i], i}}' | sort -rn;};f"
# summary: print a helpful summary of some typical metrics
summary = "!f() { \
printf \"Summary of this branch...\n\"; \
printf \"%s\n\" $(git rev-parse --abbrev-ref HEAD); \
printf \"%s first commit timestamp\n\" $(git log --date-order --format=%cI | tail -1); \
printf \"%s latest commit timestamp\n\" $(git log -1 --date-order --format=%cI); \
printf \"%d commit count\n\" $(git rev-list --count HEAD); \
printf \"%d date count\n\" $(git log --format=oneline --format=\"%ad\" --date=format:\"%Y-%m-%d\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
printf \"%d tag count\n\" $(git tag | wc -l); \
printf \"%d author count\n\" $(git log --format=oneline --format=\"%aE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
printf \"%d committer count\n\" $(git log --format=oneline --format=\"%cE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}'); \
printf \"%d local branch count\n\" $(git branch | grep -v \" -> \" | wc -l); \
printf \"%d remote branch count\n\" $(git branch -r | grep -v \" -> \" | wc -l); \
printf \"\nSummary of this directory...\n\"; \
printf \"%s\n\" $(pwd); \
printf \"%d file count via git ls-files\n\" $(git ls-files | wc -l); \
printf \"%d file count via find command\n\" $(find . | wc -l); \
printf \"%d disk usage\n\" $(du -s | awk '{print $1}'); \
printf \"\nMost-active authors, with commit count and %%...\n\"; git log-of-count-and-email | head -7; \
printf \"\nMost-active dates, with commit count and %%...\n\"; git log-of-count-and-day | head -7; \
printf \"\nMost-active files, with churn count\n\"; git churn | head -7; \
}; f"
### REF ALIASES ###
ref-recent = "!git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname:short) %(objectname:short) %(contents:subject)' refs/heads/"
### LOOKUP ALIASES ###
# whois: given a string for an author, try to figure out full name and email:
whois = "!sh -c 'git log --regexp-ignore-case -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -"
# Given any git object, try to show it briefly
whatis = show --no-patch --pretty='tformat:%h (%s, %ad)' --date=short
# Show who contributed with summarized changes
who = shortlog --summary --
# Show who contributed, in descending order by number of commits
whorank = shortlog --summary --numbered --no-merges
# List all issues mentioned in commit messages between range of commits
#
# Replace `\\\"ISSUE-[0-9]\\+\\\"` regular expression with one matching your issue tracking system.
# For Jira it should be as simple as putting your project name in place of `ISSUE`.
#
# Best used with tags:
# $ git issues v1.0..v1.1
#
# But will work with any valid commit range:
# $ git issues master..HEAD
issues = !sh -c \"git log $1 --oneline | grep -o \\\"ISSUE-[0-9]\\+\\\" | sort -u\"
# Show the commit's parents
commit-parents = !"f(){ git cat-file -p \"${*:-HEAD}\" | sed -n '/0/,/^ *$/{/^parent /p}'; };f"
# Is the commit a merge commit? If yes exit 0, else exit 1
commit-is-merge = !"f(){ [ -n \"$(git commit-parents \"$*\" | sed '0,/^parent /d')\" ];};f"
# Show the commit's keyword-marked lines.
#
# Show each line in the commit message that starts with zero or more blanks,
# then a keyword (alphanum and dash characters), then a colon.
#
# Example commit:
#
# commit ce505d161fccdbc8d4bf12047846de7433ad6d04
# Author: Joel Parker Henderson <[email protected]>
# Date: Tue May 28 11:53:47 2019 -0700
#
# Add feature foo
#
# This commit is to add feature foo.
#
# Time: 5 hours
# Cost: 600 USD
#
# Command:
#
# $ git commit-message-key-lines ce505d161fccdbc8d4bf12047846de7433ad6d04
# Commit: ce505d161fccdbc8d4bf12047846de7433ad6d04
# Author: Joel Parker Henderson <[email protected]>
# Date: Tue May 28 11:53:47 2019 -0700
# Time: 5 hours
# Cost: 600 USD
#
# Normalize the output:
#
# * Start the output with "Commit: <commit>"
#
# * Omit leading blanks
#
# * After the colon, use one space (not tab, not multiple spaces, etc.)
#
# Known issues:
#
# * TODO: improve the keyword matcher so it requires the keyword to end
# in an alphanum (not a dash), and also so the dash is a separator i.e.
# the matcher does not accept a dash followed by another dash.
#
commit-message-key-lines = "!f(){ echo \"Commit: $1\"; git log \"$1\" --format=fuller | grep \"^[[:blank:]]*[[:alnum:]][-[:alnum:]]*:\" | sed \"s/^[[:blank:]]*//; s/:[[:blank:]]*/: /\"; }; f"
### WORKFLOW ALIASES ###
# Clone a git repository including all submodules
cloner = clone --recursive
# Clone as lean as possible, for example to checkout just one subdiretory.
#
# This skips fetching unneeded objects from the server.
#
# Command breakdown:
#
# * --depth 1 does a shallow clone and implies --single-branches
#
# * --filter=blob:none skips all blobs, but fetches all tree objects
#
# * --filter=tree:0 skips unneeded trees
#
# * --filter=combine:FILTER1+FILTER2 is the syntax to use multiple
# filters at once; trying to pass --filter multiple times fails
# with: "multiple filter-specs cannot be combined".
#
# This uses --filter=tree:0 added in Git 2.20 and --filter=combine
# composite filter added in Git 2.24.
#
# The server should be configured with:
#
# git config --local uploadpack.allowfilter 1
# git config --local uploadpack.allowanysha1inwant 1
#
# An extension was made to the Git remote protocol to support this
# feature in v2.19.0 and actually skip fetching unneeded objects.
# There was server support then, but it can be locally tested.
#
# Credit: https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934
#
clone-lean = clone --depth 1 --filter=combine:blob:none+tree:0 --no-checkout
# Stash aliases for push & pop
#
# Note that if you are using an older version of git, before 2.16.0,
# then you can use the older "stash save" instead of the newer "stash push".
save = stash push
pop = stash pop
# Stash snapshot - from http://blog.apiaxle.com/post/handy-git-tips-to-stop-you-getting-fired/
# Take a snapshot of your current working tree without removing changes.
# This is handy for refactoring where you can't quite fit what you've done
# into a commit but daren't stray too far from now without a backup.
#
# Running this:
#
# $ git snapshot
#
# Creates this stash:
#
# stash@{0}: On feature/handy-git-tricks: snapshot: Mon Apr 8 12:39:06 BST 2013
#
# And seemingly no changes to your working tree.
#
snapshot = !git stash push "snapshot: $(date)" && git stash apply "stash@{0}"
# When you're a little worried that the world is coming to an end
panic = !tar cvf ../panic.tar *
# Create an archive file of everything in the repo
archive = !"f() { top=$(rev-parse --show-toplevel); cd $top; tar cvf $top.tar $top ; }; f"
# Do everything we can to synchronize all changes for the current branch.
#
# * git get: fetch and prune, pull and rebase, then update submodules
# * git put: commit all items, then push
#
# If you want to preserve merges, then we recommend you set this:
#
# git config pull.rebase preserve
#
# TODO: handle tags, delete superfluous branches, and add error handing.
#
get = !git fetch --prune && git pull --rebase && git submodule update --init --recursive
put = !git commit --all && git push
# Do everything we can to make the local repo like the master branch.
#
# TODO: handle tags, and delete superfluous branches, and add error handling.
#
mastery = !git checkout master && git fetch origin --prune && git reset --hard origin/master
# Ignore all untracked files by appending them to .gitignore:
ignore = "!git status | grep -P \"^\\t\" | grep -vF .gitignore | sed \"s/^\\t//\" >> .gitignore"
# Do a push/pull for just one branch
push1 = "!git push origin $(git branch-name)"
pull1 = "!git pull origin $(git branch-name)"
# Track and untrack, with default parameters, and with printing the command
track = "!f(){ branch=$(git rev-parse --abbrev-ref HEAD); cmd=\"git branch $branch -u ${1:-origin}/${2:-$branch}\"; echo $cmd; $cmd; }; f"
untrack = "!f(){ branch=$(git rev-parse --abbrev-ref HEAD); cmd=\"git branch --unset-upstream ${1:-$branch}\"; echo $cmd; $cmd; }; f"
# Track all remote branches that aren't already being tracked;
# this is a bit hacky because of the parsing, and we welcome
# better code that works using more-specific git commands.
track-all-remote-branches = !"f() { git branch -r | grep -v ' -> ' | sed 's/^ \\+origin\\///' ; }; f"
##
# Reset & Undo
##
# Reset and undo aliases are ways to move backwards on the commit chain.
# We find that novices prefer the wording "undo"; experts prefer "reset".
reset-commit = reset --soft HEAD~1
reset-commit-hard = reset --hard HEAD~1
reset-commit-clean = !git reset --hard HEAD~1 && git clean -fd
reset-to-pristine = !git reset --hard && git clean -ffdx
reset-to-upstream = !git reset --hard $(git upstream-name)
# Undo is simply a synonym for "reset" because "undo" can help novices.
undo-commit = reset --soft HEAD~1
undo-commit-hard = reset --hard HEAD~1
undo-commit-clean = !git reset --hard HEAD~1 && git clean -fd
undo-to-pristine = !git reset --hard && git clean -ffdx
undo-to-upstream = !git reset --hard $(git upstream-name)
# Nicknames
uncommit = reset --soft HEAD~1
unadd = reset HEAD
unstage = reset HEAD
# Discard changes in a (list of) file(s) in working tree
discard = checkout --
# Clean and discard changes and untracked files in working tree
cleanout = !git clean -df && git checkout -- .
# Expunge a file everywhere; this command is typically for a serious problem,
# such as accidentally committing a file of sensitive data, such as passwords.
# After you use command, you will likely need to force push everything.
# See https://help.github.com/articles/removing-sensitive-data-from-a-repository/
expunge = !"f() { git filter-branch --force --index-filter \"git rm --cached --ignore-unmatch $1\" --prune-empty --tag-name-filter cat -- --all }; f"
# Edit all files of the given type
edit-cached = !"f() { git ls-files --cached | sort -u ; }; `git var GIT_EDITOR` `f`"
edit-deleted = !"f() { git ls-files --deleted | sort -u ; }; `git var GIT_EDITOR` `f`"
edit-others = !"f() { git ls-files --others | sort -u ; }; `git var GIT_EDITOR` `f`"
edit-ignored = !"f() { git ls-files --ignored | sort -u ; }; `git var GIT_EDITOR` `f`"
edit-killed = !"f() { git ls-files --killed | sort -u ; }; `git var GIT_EDITOR` `f`"
edit-modified = !"f() { git ls-files --modified | sort -u ; }; `git var GIT_EDITOR` `f`"
edit-stage = !"f() { git ls-files --stage | cut -f2 | sort -u ; }; `git var GIT_EDITOR` `f`"
# Editing and adding conflicted files: when we get many merge conflicts
# and want to quickly solve them using an editor, then add the files.
edit-unmerged = !"f() { git ls-files --unmerged | cut -f2 | sort -u ; }; `git var GIT_EDITOR` `f`"
add-unmerged = !"f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
# Ours & Theirs - easy merging when you know which files you want
#
# Sometimes during a merge you want to take a file from one side wholesale.
#
# The following aliases expose the ours and theirs commands which let you
# pick a file(s) from the current branch or the merged branch respectively.
#
# * ours: checkout our version of a file and add it
# * theirs: checkout their version of a file and add it
#
# N.b. the function is there as hack to get $@ doing
# what you would expect it to as a shell user.