forked from 0xAX/git-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-cheat
executable file
·613 lines (484 loc) · 13.7 KB
/
git-cheat
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
#!/bin/bash
# command line argument
ARG=$1
# colors
e=$(printf "\e")
GREEN="$e[0;32m"
NO_COLOR="$e[0;0m"
#
# prints usage of git-cheat
#
function usage {
cat <<END
Usage: git-cheat [option]
Mandatory arguments:
$GREEN --config -c $NO_COLOR --> git configuration $NO_COLOR
$GREEN --init -i $NO_COLOR --> creation of new project $NO_COLOR
$GREEN --add -a $NO_COLOR --> adding files to git $NO_COLOR
$GREEN --delete -d $NO_COLOR --> deleting files from git $NO_COLOR
$GREEN --commit -cm $NO_COLOR --> git commit helper $NO_COLOR
$GREEN --branch -b $NO_COLOR --> git branching info $NO_COLOR
$GREEN --merge -m $NO_COLOR --> git merging info $NO_COLOR
$GREEN --rebase -rb $NO_COLOR --> git rebase info $NO_COLOR
$GREEN --update -u $NO_COLOR --> updating current repo $NO_COLOR
$GREEN --stash -st $NO_COLOR --> stashing in current repo $NO_COLOR
$GREEN --inspect -in $NO_COLOR --> git inspection, log,show... $NO_COLOR
$GREEN --remote -r $NO_COLOR --> git remote helper $NO_COLOR
$GREEN --patch -p $NO_COLOR --> git patching helper $NO_COLOR
$GREEN --debug -dg $NO_COLOR --> git debugging $NO_COLOR
$GREEN --email -e $NO_COLOR --> git email helper $NO_COLOR
$GREEN --tags -t $NO_COLOR --> git tags helper $NO_COLOR
$GREEN --reset -rs $NO_COLOR --> git reset helper $NO_COLOR
$GREEN --conflict -cn $NO_COLOR --> git conflict resolving helper $NO_COLOR
$GREEN --revert -rv $NO_COLOR --> git reverting helper $NO_COLOR
$GREEN --fix-mistakes -fm$NO_COLOR --> fix mistakes in git $NO_COLOR
$GREEN --submodules -sm $NO_COLOR --> git submodules helper $NO_COLOR
$GREEN --archive -ar $NO_COLOR --> archive your repo $NO_COLOR
$GREEN --help -h ? $NO_COLOR --> prints usage of git-cheat $NO_COLLOR
$GREEN --version -v $NO_COLOR --> prints version of git-cheat $NO_COLOR
Report bugs and contribution at: https://github.com/0xAX/git-cheat
END
}
function config {
cat <<END
git configuration
=================
git config -e [--global]
edit the .git/config [or ~/.gitconfig] file in your \$EDITOR.
git config --global user.name 'Name SecondName'
sets your name.
git config --global user.email '[email protected]'
sets your email.
git config core.autocrlf true
this setting tells git to convert the newlines to the system's standard
when checking out files, and to LF newlines when committing in.
git config --list
prints list of all config options.
git config apply.whitespace nowarn
to ignore whitespace.
END
}
function init {
cat <<END
git repository getting and creation
===================================
git init
create new repository in the current dir.
'git clone ssh://[email protected]/repo.git'
clone an existing repository to the repo dir.
'git clone ssh://[email protected]/repo.git <my-repo>'
clone an existing repository to the <my-repo> dir.
'git clone ssh://[email protected]/repo.git --branch <my-branch>'
clone an existing repository to the repo dir with checkouting <my-branch>
instead of the remote's HEAD.
'git clone ssh://[email protected]/repo.git --depth 1'
clone an existing repository to the repo dir without history only with last
commit.
END
}
function add {
cat <<END
adding files to the git
=======================
git add <file1> <file2> ...
add <file1>, <file2>, etc... to the project.
git add <dir>
add <dir> to the project.
git add .
add all files besides included in .gitignore.
git add -i
add modified contents in the working tree interactively to the index.
END
}
function delete {
cat <<END
deleting files from the git repository
======================================
git rm <file1> <file2> ...
remove <file1>, <file2>, etc... from the project.
git rm '\$(git ls-files --deleted)'
remove all deleted files from the project.
git rm --cached <file1> <file2> ...
only remove from the index.
git rm -r <dir>
remove <dir> from the project.
END
}
function commit {
cat <<END
git commiting
=============
git commit <file1> <file2> ... [-m <msg>]
commit <file1>, <file2>, etc..., optionally using commit message <msg>.
otherwise opening your editor to let you type a commit message.
git commit -a
commit all files changed since your last commit.
git commit -v
commit verbosely, i.e. includes the diff of the contents being committed in
the commit message screen.
END
}
function branch {
cat <<END
git branching
=============
git branch
list all local branches.
git branch -r
list all remote branches.
git branch -a
list all local and remote branches.
git branch <branch>
create a new branch named <branch>, referencing the same point in history
as the current branch.
git branch --track <branch> <remote-branch>
create a tracking branch. Will push/pull changes to/from another
repository.
git branch --set-upstream <branch> <remote-branch>
make an existing branch track a remote branch.
git branch -d <branch>
remove local branch.
git branch -r -d <remote-branch>
delete a remote tracking branch.
git checkout <branch>
make the current branch - <branch>.
git checkout -b <new> <start-point>
create a new branch <new> referencing <start-point>, and check it out.
git push :<branch>
remove remote <branch> from current repo.
git branch -r -d <remote-branch>
delete a remote tracking branch.
END
}
function merge {
cat <<END
git merging
===========
git merge <branch>
merge <branch> with current branch.
git merge <branch> --no-commit
merge branch <branch> into the current branch, but do not autocommit.
git merge <branch>
merge <branch> with current branch.
END
}
function rebase {
cat <<END
git rebase
==========
git rebase <branch>
rebase <branch> with current branch
git rebase master <branch>
rebase branch <branch> into the current branch
git rebase --continue
Restart the rebasing process after having resolved a merge conflict.
git rebase --abort
Alternatively, you can undo the git rebase with option --abort.
END
}
function update {
cat <<END
updating current repository
===========================
git fetch <remote>
update the remote-tracking branches for <remote> (defaults to 'origin').
Does not initiate a merge into the current branch.
git pull
fetch changes from the server, and merge them into the current branch.
git push
merge <branch> with current branch.
git push origin <branch>
update the server with your commits across all branches that are common
between your local copy and the server.
END
}
function stash {
cat <<END
git stashing
============
git stash
save your local modifications to a new stash.
git stash save <optional-name>
save your local modifications to a new stash with <optional-name>.
git stash apply
restore the changes recorded in the stash on top of the current working
tree state.
git stash pop
restore the changes from the most recent stash.
git stash list
list all current stashes.
git stash drop <stash-name>
delete the stash with <stash-name>.
git stash clear
delete all current stashes.
END
}
function inspect {
cat <<END
getting info about git repository
=================================
git log
show recent commits, most recent on top. Useful options:
--color with color
--graph with an ASCII-art commit graph on the left
--decorate with branch and tag names on appropriate commits
--stat with stats (files changed, insertions, and deletions)
-p with full diffs
--author=foo only by a certain author
--after='MMM DD YYYY' ex. ('un 20 2008') only commits after a certain date
--before='MMM DD YYYY' only commits that occur before a certain date
--merge only the commits involved in the current merge conflicts
git status
show files added to the staging area, files with changes, and untracked
files.
git diff
show a diff of the changes made since your last commit.
git log <ref1>..<ref2>
show commits between the <ref1> and <ref2>.
git log number
show last number commits.
git show <rev>
show the changeset (diff) of a commit specified by <rev>.
git show --name-only <rev>
show only the names of the files that changed, no diff information.
git ls-files
list all files in the index and under version control.
END
}
function remote {
cat <<END
git remotes
===========
git remote add <remote> <remote_URL>
adds a remote repository to your git config.
git push <repository> +<remote>:<new_remote>
replace a <remote> branch with <new_remote>.
git remote add -t master -m master origin git://example.com/git.git/
add a remote and track its master.
git remote show <remote>
show information about remote server.
git checkout -b <local branch> <remote>/<remote branch>
Track a remote branch as a local branch.
END
}
function patch {
cat <<END
git patching
============
git format-patch HEAD^
generate the last commit as a patch that can be applied on another
clone (or branch) using 'git am'.
git format-patch <rev>^..<rev>
generate a patch for a single commit.
git am <patch file>
apply the patch file generated by format-patch.
git diff --no-prefix > patchfile
generate a patch file that can be applied using patch: patch -p0 <
patchfile.
END
}
function debug {
cat <<END
git debugging
=============
git blame <file>
show who authored each line in <file>.
git blame <file> <rev>
show who authored each line in <file> as of <rev>.
git grep -e <regexp> <my_other_branch> -- '*.erl'
search for our regexp in erlang files from <my-another-branch>.
git grep --cached -e <regexp>
search files registered in the index, rather than the working tree.
git log -G <regexp>
search for commits whose changes include your regexp.
END
}
function email {
cat <<END
git email
=========
git send-email -1
send last commit from the current branch.
git send-email -1 <rev>
send commit with hash - <rev>.
git send-email configuration:
git config --global sendemail.smtpencryption tls
git config --global sendemail.smtpserver mail.smtp.com
git config --global sendemail.smtpuser [email protected]
git config --global sendemail.smtpserverport 587
git config --global sendemail.smtppass password
git config sendemail.to [email protected]
END
}
function tags {
cat <<END
git tags
========
git tag -l
list all tags defined in the repository.
git co <tag_name>
checkout the code for a particular tag.
git tag -a -m 'Tagging release 1.0' v1.0
create tag with message.
git tag -d <tag>
remove local tag <tag>.
git push origin --tags
push local tags to the remote server.
git push origin :refs/tags/<tag>
remove tag <tag> from remote server.
END
}
function reset {
cat <<END
git reseting
============
git reset HEAD <file1> <file2> ...
remove the specified files from the next commit.
END
}
function conflict {
cat <<END
git conflicts fixing
====================
git mergetool
work through conflicted files by opening them in your mergetool.
END
}
function revert {
cat <<END
git reverting
=============
git revert <rev>
reverse commit specified by <rev> and commit the result..
git checkout <file>
re-checkout <file>, overwriting any local changes.
git checkout -- <file>
undo last changes in unstaged <file>.
git checkout .
recheckout all files.
END
}
function fix-mistakes {
cat <<END
fixing mistakes
===============
git reset --hard
abandon everything since your last commit.
git reset --soft HEAD^
undo your last commit, but keep the changes in the staging area for
editing.
git commit --amend
redo previous commit, including changes you've staged in the meantime.
END
}
function submodules {
cat <<END
git submodules
=================
git submodule add <remote_repository> <path/to/submodule>
add the given repository at the given path.
git submodule update [--init]
update the registered submodules (clone missing submodules, and checkout
the commit specified by the super-repo).
removing submodules:
1. Delete the relevant line from the .gitmodules file
2. Delete the relevant section from .git/config
3. Run git rm --cached path_to_submodule
4. Commit and delete the now untracked submodule files
Updating git submodule
cd <path to submodule>
git pull
cd <path to toplevel>
git commit -m 'update submodule version'
recheckout all files
END
}
function archive {
cat <<END
archive your git repository
===========================
git checkout .
recheckout all files.
git checkout .
recheckout all files.
git checkout .
recheckout all files.
END
}
case "$ARG" in
--config | -c)
config
;;
--init | -i)
init
;;
--add | -a)
add
;;
--delete | -d)
delete
;;
--commit | -cm)
commit
;;
--branch | -b)
branch
;;
--merge | -m)
merge
;;
--rebase | -rb)
rebase
;;
--update | -u)
update
;;
--stash | -st)
stash
;;
--inspect | -in)
inspect
;;
--remote | -r)
remote
;;
--patch | -p)
patch
;;
--debug | -dg)
debug
;;
--email | -e)
email
;;
--tags | -t)
tags
;;
--reset | -rs)
reset
;;
--conflict | -cn)
conflict
;;
--revert | -rv)
revert
;;
--fix-mistakes | -fm)
fix-mistakes
;;
--submodules | -sm)
submodules
;;
--archive | -ar)
archive
;;
--help | -h)
usage
;;
--version | -v)
echo "git-cheat-1.0"
;;
*)
usage
;;
esac