-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgit.plugin.nu
More file actions
669 lines (525 loc) · 12.1 KB
/
Copy pathgit.plugin.nu
File metadata and controls
669 lines (525 loc) · 12.1 KB
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
###################################
# Git shortcuts #
###################################
def g [...args: string] {
git ...$args
}
def ga [...args: string] {
git add ...$args
}
def gaa [] {
git add --all
}
def gai [...args: string] {
git add --interactive ...$args
}
def gam [message] {
# Amend commit; modify commit message, optionally 'git add' files
git commit --amend -m $message
}
def gama [message] {
# Amend commit; modify commit message, and add all modified files
git commit --amend -am $message
}
def gan [] {
# Amend commit; keep commit message, optionally 'git add' files
git commit --amend --no-edit
}
def gana [] {
# Amend commit; keep commit message, and add all modified files
git commit --amend --no-edit -a
}
def gap [...args: string] {
git add --patch ...$args
}
def gb [...args: string] {
git branch ...$args
}
def gba [] {
# List all branches
git branch --all
}
def gbd [...args: string] {
git branch --delete ...$args
}
def gbdf [...args: string] {
git branch --delete --force ...$args
}
def gbl [...args: string] {
git blame ...$args
}
def gbls [] {
# List all branches
git branch --all
}
def gbs [...args: string] {
git bisect ...$args
}
def gbsb [...args: string] {
git bisect bad ...$args
}
def gbsg [...args: string] {
git bisect good ...$args
}
def gbsr [] {
git bisect reset
}
def gbss [] {
git bisect start
}
def gc [...args: string] {
git commit --verbose ...$args
}
def gcam [...args: string] {
git commit -am ...$args
}
def gcame [] {
git commit --allow-empty-message -am ""
}
def gcamg [...args: string] {
git commit --gpg-sign -am ...$args
}
def gcams [...args: string] {
git commit --signoff -am ...$args
}
def gcamu [] {
git commit -am "Update"
}
def gcem [...args: string] {
# Create empty commit for testing CI/CD
git commit --allow-empty -m ...$args
}
def gcf [...args: string] {
git config ...$args
}
def gcfg [...args: string] {
git config --global ...$args
}
def gcfl [...args: string] {
git config --local ...$args
}
def gcfls [...args: string] {
git config --list ...$args
}
def gcl [url, path?] {
# Git clone and cd into project
if ($path != null) {
git clone --recurse-submodules $url $path
cd $path
} else {
git clone --recurse-submodules $url
cd ($url | path parse | get stem)
}
}
def gcm [...args: string] {
git commit -m ...$args
}
def gcmg [...args: string] {
git commit --gpg-sign -m ...$args
}
def gcms [...args: string] {
git commit --signoff -m ...$args
}
def gcnt [] {
# Count commits on current branch
git shortlog -sn
echo " + ___________________________________"
echo " (git rev-list --count HEAD) commits total up to current HEAD"
}
def gco [...args: string] {
git checkout ...$args
}
def gcob [...args: string] {
git checkout -b ...$args
}
def gcobb [] {
# Checkout previous branch
git checkout -
}
def gcoc [count = 1] {
# Checkout child commit
# Usage: gcoc = gcoc 1 => direct child; gcoc 2 => grandchild
let children = (git log --all --ancestry-path ^HEAD --format=format:%H | lines)
if ($children | is-empty) {
echo "This commit does not have any children, HEAD remains at:"
git log -1 --oneline
return
}
mut child = ($children | last $count | first)
if ($children | length) <= $count {
let branches = (git branch --contains $child | each { |it| $it | str trim | str replace '*' '' } | str join ' ')
if ($branches | str contains ' ') == false {
$child = $branches
}
}
git checkout $child
}
def gcod [] {
git checkout develop
}
def gcof [...args: string] {
git checkout -f ...$args
}
def gcom [] {
git checkout (git_main_branch)
}
def gcop [count = 1] {
# Checkout parent commit
# Usage: gcop = gcop 1 => direct parent; gcop 2 => grandparent
git checkout $"HEAD~($count)"
}
def gcp [...args: string] {
git cherry-pick ...$args
}
def gcpa [] {
git cherry-pick --abort
}
def gcpc [] {
git cherry-pick --continue
}
def gcpq [] {
git cherry-pick --quit
}
def gcps [] {
git cherry-pick --skip
}
def gd [...args: string] {
git diff ...$args
}
def gds [...args: string] {
git diff --staged ...$args
}
def gdst [...args: string] {
# Show diff between latest stash and working tree
git diff 'stash@{0}' ...$args
}
def gdsth [] {
# Show diff between latest stash and HEAD
git diff 'stash@{0}' HEAD
}
def gdstp [] {
# Show diff between latest stash and its parent
git diff 'stash@{0}^' 'stash@{0}'
}
def gf [...args: string] {
git fetch ...$args
}
def gfo [...args: string] {
git fetch origin ...$args
}
def gg [...args: string] {
# Git graph (all commits)
git log --graph --all --date=format:"%d/%m/%Y" --format=format:"%C(yellow)%h%Creset%x09%C(dim white)%an%Creset%x09%C(bold green)%D%Creset%n%C(white)%ad%Creset%x09%C(bold)%s%Creset%n" ...$args
}
def ggb [...args: string] {
# Git graph branches
gg "--simplify-by-decoration" ...$args
}
def ggbo [...args: string] {
# Git graph branches --oneline
ggo "--simplify-by-decoration" ...$args
}
def ggo [...args: string] {
# Git graph --oneline (all commits)
git log --graph --all --date=format:"%d/%m/%Y" --format=format:"%C(yellow)%h%Creset %C(white)%ad%Creset %C(bold)%s %C(bold green)%D%Creset%n" ...$args
}
def gig [...args: string] {
# Ignore tracked files
git update-index --skip-worktree ...$args
}
def gug [...args: string] {
# Unignore files
git update-index --no-skip-worktree ...$args
}
def glsig [] {
# List ignored files
git ls-files -v | where $it =~ '^S'
}
def gl [] {
# Git log --name-status (defaults to last 10 commits)
glog 10
}
def glo [] {
# Git log --oneline
git log --date=format:"%d/%m/%Y" --format=format:"%C(yellow)%h%Creset %C(white)%ad%Creset %C(bold)%s %C(bold green)%D%Creset"
}
def glog [count?: int, ...args: string] {
# Git log with formatting; defaults to full log, pass count for N commits
echo ""
if ($count != null) {
git log $"-($count)" --reverse --name-status --date=format:"%A %B %d %Y at %H:%M" --format=format:"%C(yellow)%H%Creset%x09%C(bold green)%D%Creset%n%<|(40)%C(white)%ad%x09%an%Creset%n%n %C(bold)%s%Creset%n%w(0,4,4)%n%-b%n" ...$args
} else {
git log --reverse --name-status --date=format:"%A %B %d %Y at %H:%M" --format=format:"%C(yellow)%H%Creset%x09%C(bold green)%D%Creset%n%<|(40)%C(white)%ad%x09%an%Creset%n%n %C(bold)%s%Creset%n%w(0,4,4)%n%-b%n" ...$args
}
echo ""
}
def glsb [] {
# List all branches
git branch --all
}
def glsf [] {
# List tracked files
git ls-files
}
def glsr [] {
# List remotes
git remote -v
}
def glss [] {
# List submodules
git config --file .gitmodules --name-only --get-regexp path
}
def glsst [...args: string] {
# List stashes
git stash list ...$args
}
def glst [...args: string] {
# List tags
git tag --list ...$args
}
def gm [...args: string] {
git merge ...$args
}
def gmnff [...args: string] {
git merge --no-ff ...$args
}
def gmom [] {
git merge $"origin/(git_main_branch)"
}
def gmum [] {
git merge $"upstream/(git_main_branch)"
}
def gmv [...args: string] {
git mv ...$args
}
def gph [...args: string] {
git push ...$args
}
def gphd [...args: string] {
# Delete remote branch
git push --delete ...$args
}
def gphdo [...args: string] {
# Delete branch from origin
git push --delete origin ...$args
}
def gphf [...args: string] {
git push --force-with-lease ...$args
}
def gphff [...args: string] {
git push --force ...$args
}
def gpht [] {
git push
if ($env.LAST_EXIT_CODE == 0) {
git push --tags
}
}
def gphu [...args: string] {
# Set upstream branch
git push -u ...$args
}
def gphuo [...args: string] {
# Set origin as upstream
git push -u origin ...$args
}
def gphuom [] {
# Set origin/main as upstream
git push -u origin main
}
def gpl [...args: string] {
git pull ...$args
}
def gpla [...args: string] {
# Pull with autostash
git pull --autostash ...$args
}
def gplr [...args: string] {
git pull --rebase ...$args
}
def gplrs [...args: string] {
git pull --recurse-submodules ...$args
}
def gr [...args: string] {
git reset ...$args
}
def grh [count, ...args: string] {
# git reset HEAD
# Usage: grh 1 => reset HEAD to previous commit; grh 2 => 2 commits back
git reset $"HEAD~($count)" ...$args
}
def grhard [...args: string] {
# Hard reset (dangerous: removes uncommitted changes)
git reset --hard ...$args
}
def grhhard [count = 1] {
# Hard reset HEAD
grh $count "--hard"
}
def grhk [count = 1] {
# Keep reset HEAD (aborts if dirty files)
grh $count "--keep"
}
def grhs [count = 1] {
# Soft reset HEAD
grh $count "--soft"
}
def grk [...args: string] {
# Keep reset (safer than --hard; aborted if dirty files)
git reset --keep ...$args
}
def grs [...args: string] {
# Soft reset
git reset --soft ...$args
}
def grb [...args: string] {
git rebase ...$args
}
def grbm [] {
git rebase (git_main_branch)
}
def gre [...args: string] {
git restore ...$args
}
def grea [] {
# Restore all (throw away uncommitted changes)
git restore .
}
def greh [path, count = 1] {
# Restore from HEAD
git restore $"--source=HEAD~($count)" $path
}
def grem [...args: string] {
git remote ...$args
}
def grema [...args: string] {
# Add remote
git remote add ...$args
}
def gremao [...args: string] {
# Add origin remote
git remote add origin ...$args
}
def gremls [] {
# List remotes
git remote -v
}
def gremrm [...args: string] {
# Remove remote
git remote rm ...$args
}
def gremrmo [] {
# Remove origin
git remote rm origin
}
def gremset [...args: string] {
# Set remote URL
git remote set-url ...$args
}
def gremseto [...args: string] {
# Set origin URL
git remote set-url origin ...$args
}
def gremsh [...args: string] {
git remote show ...$args
}
def gremv [] {
# List remotes
git remote -v
}
def grl [...args: string] {
git reflog ...$args
}
def grm [...args: string] {
git rm ...$args
}
def gs [...args: string] {
git status ...$args
}
def gsh [...args: string] {
git show ...$args
}
def gss [] {
git status --short
}
def gst [...args: string] {
git stash ...$args
}
def gsta [...args: string] {
git stash apply ...$args
}
def gstd [...args: string] {
git stash drop ...$args
}
def gstls [...args: string] {
git stash list ...$args
}
def gstph [...args: string] {
git stash push ...$args
}
def gstpp [...args: string] {
git stash pop ...$args
}
def gstshl [] {
# Show stash diff
git stash show -l
}
def gstshp [] {
# Show stash patch
git stash show -p
}
def gsub [...args: string] {
git submodule ...$args
}
def gsuba [...args: string] {
git submodule add ...$args
}
def gsubi [...args: string] {
# Initialize submodules
git submodule update --init ...$args
}
def gsubf [...args: string] {
git submodule foreach ...$args
}
def gsubfpl [] {
git submodule foreach git pull
}
def gsubfplom [] {
git submodule foreach git pull origin (git_main_branch)
}
def gsubs [...args: string] {
git submodule status ...$args
}
def gsubu [...args: string] {
# Update submodules
git submodule update --remote --merge ...$args
}
def gt [...args: string] {
git tag ...$args
}
def gtam [...args: string] {
# Annotated tag with message
git tag -am ...$args
}
def gtd [...args: string] {
git tag --delete ...$args
}
def gtls [...args: string] {
git tag --list ...$args
}
def gtsm [...args: string] {
# GPG signed tag
git tag -sm ...$args
}
########################################
# Git Utility Functions #
########################################
def git_main_branch [] {
# Check if main branch exists, otherwise use master branch
let branches = (git branch --list main | lines)
if ($branches | length) > 0 {
"main"
} else {
"master"
}
}