-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitconfig
215 lines (196 loc) · 8.33 KB
/
.gitconfig
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
[user]
name = Ben Lu
email = [email protected]
[merge]
tool = nvimdiff
[color]
ui = true
# [color "diff"]
# meta = blue
# https://stackoverflow.com/questions/26941144/how-do-you-customize-the-color-of-the-diff-header-in-git-diff
#new = "#55ee55 green bold"
[alias]
alias = ! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /
# To checkout a file from another branch, git co <branch> -- file
# To show a file from another branch, git show <branch>:file
#
# https://stackoverflow.com/questions/5188320/how-can-i-get-a-list-of-git-branches-ordered-by-most-recent-commit
# To amend an older commit: https://stackoverflow.com/questions/3103589/how-can-i-easily-fixup-a-past-commit
# git commit -a --fixup 1edb09da623
# git rebase -i --autosquash origin/master
# OR:
# git stash # temporarily put my work aside
# git rebase -i <bad_commit>~1 # rebase one step before the bad commit
# # mark broken commit for editing
# vim <affected_sources> # fix the bug
# git add <affected_sources> # stage fixes
# git commit -C <bad_commit> # commit fixes using same log message as before
# git rebase --continue # base all later changes onto this
# Merge conflict for generated files: `git co --theirs .`
# Also consider --ours, and `git r -X theirs`
aa = add -A
amend = commit -a --amend --no-edit
abandon = !BRANCH=`git rev-parse --abbrev-ref HEAD` && git reset --hard && git checkout $(git mainmaster) && git branch -D $BRANCH
# get main branch
#bm = !git remote show upstream | grep "HEAD branch" | sed 's/.*: //'
#bm = symbolic-ref --short HEAD
b = 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))'
base = !git merge-base HEAD $(git upstream)
# Branch Name
bn = rev-parse --abbrev-ref HEAD
# Include remote branches
bo = for-each-ref --sort=committerdate refs/heads/ refs/remotes/origin/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
# bo no formatting (for deleting old ones
boq = for-each-ref --sort=committerdate refs/remotes/origin/ --format='%(refname:lstrip=-1)'
# Local branches
bl = log --branches --oneline --no-walk --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr - %cd) %C(bold blue)<%an>%Creset'
# All remote branches
blo = !git for-each-ref --sort=committerdate refs/heads/ refs/remotes/origin/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
# To clean everything
cfd = clean -fd
ci = commit -am
cm = commit -m
cf = commit -a --fixup
co = checkout
# git cherry-pick A^..B # A to B inclusive
# git cod 'Dec 25 2018'
cod = !"f() { echo git checkout `git rev-list -1 --before=\"$1\" --first-parent $(git upstream)`; }; f"
# checkout original
coo = "!git checkout $(git mb)"
count-lines = "! author=\"$1\"; shift; git log --author=\"$author\" --pretty=tformat: --numstat \"$@\" | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\\n\", add, subs, loc }' #"
# only works on git repos that you cloned
default = !"basename $(git symbolic-ref --short refs/remotes/origin/HEAD)"
d = diff
dbase = "!f() { git diff $(git merge-base HEAD \"$@\");}; f"
diff-name = !git diff $(git merge-base HEAD origin/$(git mainmaster)) --diff-filter=d --name-only
ds = diff --staged
dh = diff HEAD
dt = difftool
# Diff upstream
#du = !git diff $(git merge-base HEAD $(git upstream))...HEAD
# Why did I need the git prefix? Must have a reason
#du = "!cd \"${GIT_PREFIX:-.}\"; git diff $(git merge-base HEAD $(git upstream))...HEAD"
du = "!git diff \"$(git mb)\""
dus = du --stat
dm = "!git diff $(git merge-base HEAD origin/$(git mainmaster))"
#du = "!f() { git diff $(git merge-base HEAD $(git upstream)) \"$@\"; }; f"
dw = d --color-words
dc = d --color-words=.
# Delete push
dp = !git push -d origin $(git rev-parse --abbrev-ref HEAD) && git p
f = fetch
fo = !git fetch origin
fou = !"git fetch origin && git branch -f $(git mainmaster) origin/$(git mainmaster)"
is-sparse = config --get core.sparseCheckout
last-message = log -1 --pretty=%B
lbase = log --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr - %cd) %C(bold blue)<%an>%Creset'
l = lbase --graph -500
ls = l --stat
ll = ls -10 -U0
la = lbase --all
laa = lbase --all --author-date-order --author='Ben Lu'
lf = l --first-parent
lfs = l --first-parent --stat
# -c shows merge commit diff too
lfsc = l -c --first-parent --stat
llfsc = ll -c --first-parent --stat
#lfa = lf --author-date-order --no-merges
mb = !git merge-base HEAD $(git upstream)
mbm = "!git merge-base HEAD origin/$(git mainmaster)"
mainmaster = !"git branch --format='%(refname:short)' | rg '^(main|master)$'"
m = merge --no-ff
mt = mergetool
# New branch
new = !"git checkout origin/$(git mainmaster) -b"
newdep = checkout -t HEAD -b
upstream = rev-parse --abbrev-ref --symbolic-full-name @{u}
p = push origin HEAD
pr = pull --rebase
# Removes deleted branches from cache: https://stackoverflow.com/questions/32147093/git-delete-remotes-remote-refs-do-not-exist
pbranch = fetch -p origin
pf = push -f origin HEAD
pt = push --tags origin HEAD
pu = push -u origin HEAD
root = rev-parse --show-toplevel
r = rebase
ra = rebase --abort
rbi = !git rebase -i $(git mb)
rc = rebase --continue
rs = restore --staged
rsw = restore --staged --worktree
# https://git-scm.com/book/en/v2/Git-Tools-Searching -L line log search is way more powerful
searchlog = log -p -G
s = status
ss = status -uno
si = status --ignored
# Source log commands if your git is slow
slog = log --no-decorate
sl = slog --oneline
sls = sl --stat
sll = sls -U0
# Commits grouped by author in the past month
stat = "shortlog --since=\"1 month ago\" -n -s --format='[%h] %s'"
stats = stat -s
# Submodule fixes
su = submodule update --init --recursive
#squash = !git rebase -i $(git merge-base HEAD origin/$(git bm))
squash = "!f(){ git reset --soft ${1:-$(git mb)} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f"
#squashrebase = !git squash && git rebase origin/$(git bm)
tc = rev-list -n 1
tracking = rev-parse --abbrev-ref --symbolic-full-name @{u}
tagsha = tag --sort taggerdate --contains
# From https://stackoverflow.com/questions/8475448/find-merge-commit-which-include-a-specific-commit
find-merge = "!sh -c 'commit=$0 && branch=${1:-HEAD} && (git rev-list $commit..$branch --ancestry-path | cat -n; git rev-list $commit..$branch --first-parent | cat -n) | sort -k2 -s | uniq -f1 -d | sort -n | tail -1 | cut -f2'"
show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n \"$merge\" ] && git show $merge'"
# Delete old branches
dell = "!git branch --merged | egrep -v '(^\\*|main|master|dev)' | xargs git branch -d"
delo = "!git branch -r --merged | grep -v 'master|main' | sed 's/origin\\///' | xargs git push --delete origin"
[core]
pager = less $LESS
excludesfile = ~/.gitignore_global
[push]
default = matching
# git reset HEAD~
# git push -f origin HEAD^:master
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[diff]
tool = nvimdiff
# Default true
renames = true
[mergetool]
keepBackup = false
# https://git-scm.com/docs/vimdiff
# default
#layout = "(LOCAL,BASE,REMOTE)/MERGED"
[mergetool "nvimdiff"]
layout = "MERGED"
[rerere]
enabled = true
[rebase]
autosquash = true
[fetch]
prune = true
[http]
postBuffer = 524288000
[init]
defaultBranch = main
# from delta page
[core]
pager = delta
[interactive]
diffFilter = delta --color-only
[delta]
navigate = true # use n and N to move between diff sections
line-numbers = true
side-by-side = true
theme = Solarized (light)
[merge]
conflictstyle = diff3
[diff]
colorMoved = default
[submodule]
recurse = true