forked from mike-rambil/Advanced-Git
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoc-source.json
More file actions
611 lines (611 loc) · 23.1 KB
/
toc-source.json
File metadata and controls
611 lines (611 loc) · 23.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
[
{
"Name": "Miscellaneous & Orphaned Git Commands",
"category": "Miscellaneous",
"short_description": "Useful Git commands and scripts not referenced elsewhere.",
"long_description": "This file collects useful Git commands and scripts that were previously only in the README and not referenced elsewhere in this repository.",
"tags": ["misc", "cleanup", "advanced"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"subtoc": [
{
"Name": "git maintenance start",
"category": "Maintenance",
"short_description": "Runs a cronJob in background for the specified repo for periodic maintenance.",
"command": "git maintenance start",
"examples": [
{
"code": "git maintenance start",
"description": "Enable background maintenance for your repository."
}
],
"steps": ["Run `git maintenance start` in your repository."],
"links": [
{
"label": "Official Docs",
"url": "https://git-scm.com/docs/git-maintenance"
}
],
"tags": ["maintenance", "automation"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "git request-pull",
"category": "Collaboration",
"short_description": "Generate a request to pull changes into a repository.",
"command": "git request-pull <start> <url> <end>",
"examples": [
{
"code": "git request-pull v1.0 https://github.com/example/repo.git v1.1",
"description": "Generate a pull request message from v1.0 to v1.1."
}
],
"steps": [
"Run `git request-pull <start> <url> <end>` to generate a pull request message."
],
"links": [
{
"label": "Official Docs",
"url": "https://git-scm.com/docs/git-request-pull"
}
],
"tags": ["collaboration", "pull-request"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "View and Clean Up Local Git Branches (Bash)",
"category": "Branch Management",
"short_description": "Scripts to view and clean up local branches using Bash.",
"examples": [
{
"code": "git branch -vv | grep -E '^\\s*\\S+\\s+[^\\[]+$'",
"description": "List local branches without a remote connection."
},
{
"code": "git branch -vv | grep -E '^\\s*\\S+\\s+[^\\[]+$' | awk '{print $1}' | xargs git branch -D",
"description": "Delete local branches without remote tracking."
}
],
"steps": [
"List local branches.",
"Delete local branches without remote.",
"View branches with deleted remote.",
"Delete stale local branches."
],
"warnings": [
"Deleting branches is irreversible. Double-check before running destructive commands."
],
"tags": ["branches", "cleanup", "bash"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "View and Clean Up Local Git Branches (PowerShell)",
"category": "Branch Management",
"short_description": "Scripts to view and clean up local branches using PowerShell.",
"examples": [
{
"code": "git branch -vv | Select-String -NotMatch \"origin/\"",
"description": "List local branches without a remote connection."
},
{
"code": "git branch -vv | Select-String -NotMatch \"origin/\" | ForEach-Object { $branch = ($_ -split \"\\s+\")[1]; git branch -D $branch }",
"description": "Delete local branches without remote tracking."
}
],
"steps": [
"List local branches.",
"Delete local branches without remote.",
"View branches with deleted remote.",
"Delete stale local branches."
],
"warnings": [
"Deleting branches is irreversible. Double-check before running destructive commands."
],
"tags": ["branches", "cleanup", "powershell"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
}
]
},
{
"Name": "Git Command Reference (Full List)",
"category": "Reference",
"short_description": "A comprehensive list of Git commands used in this project.",
"long_description": "A comprehensive list of Git commands used in this project, formatted according to our standard.",
"tags": ["reference", "all-commands"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"subtoc": [
{
"Name": "git init --bare",
"category": "Repository Management",
"short_description": "Initialize a bare repository, typically used for remote repositories.",
"command": "git init --bare my-repo.git",
"examples": [
{
"code": "git init --bare my-repo.git",
"description": "Create a bare repository for collaboration."
}
],
"steps": [
"Run `git init --bare my-repo.git` to create a bare repository."
],
"tags": ["init", "bare", "repository"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "git clone --mirror <repository>",
"category": "Repository Management",
"short_description": "Clone a repository in mirror mode, including all refs and branches.",
"command": "git clone --mirror https://github.com/example/repo.git",
"examples": [
{
"code": "git clone --mirror https://github.com/example/repo.git",
"description": "Create a full backup or migration of a repository."
}
],
"steps": [
"Run `git clone --mirror <repository>` to create a full backup or migration."
],
"tags": ["clone", "mirror", "backup"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
}
]
},
{
"Name": "Useful Rare Git Commands You Never Heard Of",
"category": "Advanced",
"short_description": "A collection of lesser-known but powerful Git commands.",
"long_description": "A collection of lesser-known but powerful Git commands. Use these to level up your Git workflow!",
"tags": ["rare", "advanced", "tips"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"subtoc": [
{
"Name": "git replace <old-commit> <new-commit>",
"category": "History",
"short_description": "Temporarily substitute one commit for another.",
"command": "git replace abc123 def456",
"examples": [
{
"code": "git replace abc123 def456",
"description": "Temporarily replace commit abc123 with def456."
}
],
"steps": [
"Run `git replace <old-commit> <new-commit>` to test or patch history."
],
"tags": ["replace", "history"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
}
]
},
{
"Name": "How to Use git push --force-with-lease Safely",
"category": "Collaboration",
"short_description": "Safely force-push to a branch without overwriting others' work.",
"long_description": "Guide to using `git push --force-with-lease` to avoid overwriting others' work when force-pushing.",
"command": "git push --force-with-lease",
"examples": [
{
"code": "git push --force-with-lease",
"description": "Safely force-push your changes."
}
],
"steps": [
"Fetch the latest changes: `git fetch origin`",
"Push with lease: `git push --force-with-lease`",
"If rejected, pull and rebase: `git pull --rebase origin main`",
"Resolve conflicts, commit, and retry push"
],
"prerequisites": ["You must have permission to push to the branch."],
"warnings": [
"Never use `--force` unless you are sure. Prefer `--force-with-lease`."
],
"links": [
{
"label": "Medium Article",
"url": "https://medium.com/@sahilsahilbhatia/git-push-force-with-lease-vs-force-ecae72601e80"
}
],
"tags": ["push", "force", "safe"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Past commits of a specific file",
"category": "History and Inspection",
"short_description": "See all commits and changes for a specific file.",
"long_description": "You can see all commits related to a specific file using Git commands. Here are a few ways to do it:",
"tags": ["history", "inspection", "file"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"subtoc": [
{
"Name": "Show Commit History of a Specific File",
"category": "History",
"command": "git log --oneline -- filename.txt",
"examples": [
{
"code": "git log --oneline -- filename.txt",
"description": "List all commits that modified `filename.txt`."
}
],
"steps": ["Lists all commits that modified `filename.txt`."],
"tags": ["log", "file", "history"],
"related_commands": [
"git log -p -- filename.txt",
"git blame filename.txt"
],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Show Detailed Commit History (With Changes)",
"category": "History",
"command": "git log -p -- filename.txt",
"examples": [
{
"code": "git log -p -- filename.txt",
"description": "Show each commit and the actual changes made to `filename.txt`."
}
],
"steps": [
"Shows each commit and the actual changes made to `filename.txt`."
],
"tags": ["log", "diff", "file"],
"related_commands": ["git log --oneline -- filename.txt"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Show Commit History With Author and Date",
"category": "History",
"command": "git log --pretty=format:\"%h - %an, %ar : %s\" -- filename.txt",
"examples": [
{
"code": "git log --pretty=format:\"%h - %an, %ar : %s\" -- filename.txt",
"description": "Display commit hash, author, relative date, and commit message."
}
],
"steps": [
"Displays commit hash, author, relative date, and commit message."
],
"tags": ["log", "author", "date"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "See Who Last Modified Each Line (Blame)",
"category": "History",
"command": "git blame filename.txt",
"examples": [
{
"code": "git blame filename.txt",
"description": "Show the last commit that changed each line of the file."
}
],
"steps": ["Shows the last commit that changed each line of the file."],
"tags": ["blame", "file", "history"],
"warnings": [
"Blame can be misleading if the file has been heavily refactored."
],
"author": "mike-rambil",
"last_updated": "2024-06-10"
}
]
},
{
"Name": "Git Clean: Remove Untracked Files and Directories",
"category": "Stashing and Cleaning",
"short_description": "Remove untracked files and directories from your repository.",
"long_description": "`git clean` is a powerful command that helps remove untracked files and directories from your repository. It is particularly useful when you want to reset your working directory without affecting committed files.",
"command": "git clean",
"flags": {
"-n": "Shows what will be deleted without actually deleting anything.",
"-f": "Forces deletion of untracked files.",
"-d": "Deletes untracked directories.",
"-i": "Interactive mode to selectively delete files.",
"-x": "Removes ignored and untracked files.",
"-X": "Removes only ignored files."
},
"examples": [
{
"code": "git clean -n -d",
"description": "Preview what will be deleted (dry run)."
},
{
"code": "git clean -f",
"description": "Delete all untracked files."
},
{
"code": "git clean -f -d",
"description": "Delete all untracked files and directories."
},
{
"code": "git clean -i",
"description": "Interactive mode for selective deletion."
}
],
"steps": [
"Preview deletions: `git clean -n -d`",
"Delete untracked files: `git clean -f`",
"Delete untracked files and directories: `git clean -f -d`",
"Interactive deletion: `git clean -i`",
"Remove ignored and untracked files: `git clean -f -x`",
"Remove only ignored files: `git clean -f -X`"
],
"prerequisites": ["Make sure you have committed all important changes."],
"warnings": [
"This will permanently delete files! Always use `-n` before `-f`.",
"Be cautious with `-x` and `-X` as they remove ignored files, which might include config files."
],
"links": [
{ "label": "Official Docs", "url": "https://git-scm.com/docs/git-clean" }
],
"tags": ["clean", "untracked", "workspace"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "How to Use git worktree Safely",
"category": "Worktree",
"short_description": "Work on multiple branches simultaneously without switching.",
"long_description": "`git worktree` allows you to manage multiple working directories linked to a single Git repository. It helps developers work on multiple branches simultaneously without switching branches in the same directory.",
"tags": ["worktree", "branches", "advanced"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"subtoc": [
{
"Name": "Check Existing Worktrees",
"category": "Worktree",
"command": "git worktree list",
"examples": [
{
"code": "git worktree list",
"description": "List all active worktrees."
}
],
"steps": ["List all active worktrees."],
"tags": ["worktree", "list"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Create a New Worktree",
"category": "Worktree",
"command": "git worktree add <path> <branch>",
"examples": [
{
"code": "git worktree add ../feature-branch feature",
"description": "Create a new worktree for the feature branch."
}
],
"steps": ["Create a worktree linked to a specific branch."],
"prerequisites": [
"The target path must not already be a git repository."
],
"tags": ["worktree", "add"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Remove a Worktree",
"category": "Worktree",
"command": "git worktree remove <worktree-path>",
"examples": [
{
"code": "git worktree remove ../feature-branch",
"description": "Detach a worktree without deleting the files."
}
],
"steps": ["Detach a worktree without deleting the files."],
"warnings": [
"Make sure you have committed all changes before removing a worktree."
],
"tags": ["worktree", "remove"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Switch Between Worktrees",
"category": "Worktree",
"command": "cd <worktree-path>",
"examples": [
{
"code": "cd ../feature-branch",
"description": "Switch to the worktree directory."
}
],
"steps": ["Simply cd into the worktree directory to switch."],
"tags": ["worktree", "switch"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Use Worktrees for Temporary Fixes",
"category": "Worktree",
"command": "git worktree add ../hotfix hotfix-branch",
"examples": [
{
"code": "git worktree add ../hotfix hotfix-branch",
"description": "Quickly apply a fix on another branch without leaving your main branch."
}
],
"steps": [
"Quickly apply a fix on another branch without leaving your main branch."
],
"tags": ["worktree", "hotfix"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Flags and Their Uses",
"flags": {
"add": "Creates a new worktree for an existing branch.",
"-b": "Creates a new worktree with a new branch.",
"list": "Lists all active worktrees.",
"remove": "Detaches a worktree from the repo without deleting files.",
"prune": "Cleans up stale worktree references after manual deletion.",
"move": "Moves a worktree to a different location."
},
"tags": ["worktree", "flags"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
}
]
},
{
"Name": "Sharing Changes as Patch Files",
"category": "Patch & Diff",
"short_description": "Generate and share patch files for committed or uncommitted changes.",
"long_description": "How to create patch files from your changes for sharing via email, SCP, Slack, or other means. Covers both committed (with full commit metadata) and uncommitted changes.",
"tags": ["patch", "diff", "sharing", "email", "collaboration"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"subtoc": [
{
"Name": "Create Patch from Last Commit(s)",
"category": "Patch & Diff",
"command": "git format-patch HEAD~1",
"examples": [
{
"code": "git format-patch HEAD~1",
"description": "Create a .patch file for the last commit."
},
{
"code": "git format-patch origin/main..HEAD --stdout > my-changes.patch",
"description": "Create a single patch file for all commits on top of main."
}
],
"steps": [
"Run 'git format-patch HEAD~1' to create a patch for the last commit.",
"Use 'git format-patch origin/main..HEAD --stdout > my-changes.patch' to create a single patch file for multiple commits."
],
"warnings": [
"Patch files created this way include commit messages, authorship, and timestamps.",
"Use 'git am' to apply these patches on another system."
],
"tags": ["patch", "format-patch", "committed"],
"links": [
{
"label": "Official Docs",
"url": "https://git-scm.com/docs/git-format-patch"
}
],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Apply Patch with Commit Metadata",
"category": "Patch & Diff",
"command": "git am my-changes.patch",
"examples": [
{
"code": "git am my-changes.patch",
"description": "Apply a patch file and preserve commit info."
}
],
"steps": [
"Run 'git am my-changes.patch' to apply the patch and preserve commit messages, authorship, and timestamps."
],
"tags": ["patch", "am", "apply"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Create Patch from Uncommitted Changes",
"category": "Patch & Diff",
"command": "git diff > changes.diff",
"examples": [
{
"code": "git diff > changes.diff",
"description": "Create a diff file of uncommitted changes."
}
],
"steps": [
"Run 'git diff > changes.diff' to save uncommitted changes to a file."
],
"warnings": [
"This does NOT preserve commit metadata or history—just raw changes."
],
"tags": ["diff", "uncommitted", "snapshot"],
"links": [
{
"label": "Official Docs",
"url": "https://git-scm.com/docs/git-diff"
}
],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Apply Diff File",
"category": "Patch & Diff",
"command": "git apply changes.diff",
"examples": [
{
"code": "git apply changes.diff",
"description": "Apply a diff file of uncommitted changes."
}
],
"steps": [
"Run 'git apply changes.diff' to apply the changes from a diff file."
],
"tags": ["diff", "apply", "uncommitted"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
},
{
"Name": "Patch vs Diff: Quick Reference",
"category": "Patch & Diff",
"long_description": "| Command | Use Case | Preserves Commit Info? | Can Apply With |\n|---|---|---|---|\n| git diff > file.diff | Share uncommitted changes | ❌ | git apply |\n| git format-patch > file.patch | Share committed changes | ✅ | git am |",
"tags": ["patch", "diff", "reference"],
"author": "mike-rambil",
"last_updated": "2024-06-10"
}
]
},
{
"Name": "Pull Changes of Specific Files from a Commit",
"category": "Selective File Restore",
"short_description": "Restore or pull changes for specific files from a past commit without reverting the entire commit.",
"long_description": "How to use git to pull or restore changes for only certain files from a specific commit, without affecting the rest of your working directory or reverting the whole commit. Useful for cherry-picking file-level changes.",
"command": "git checkout <commit-hash> -- <file1> <file2>",
"examples": [
{
"code": "git checkout e8ab7f64fdfcc7bdaaed8d96c0ac26dce035663f -- path/to/file1.txt path/to/file2.txt",
"description": "Restore file1.txt and file2.txt from the specified commit."
},
{
"code": "git add path/to/file1.txt path/to/file2.txt\ngit commit -m \"Pulled changes for file1.txt and file2.txt from commit e8ab7f64\"\ngit push origin revert/productionOrder",
"description": "Stage, commit, and push the restored files to a new branch."
}
],
"steps": [
"Checkout the specific files from the desired commit using 'git checkout <commit-hash> -- <file1> <file2>'.",
"Stage the changes with 'git add <file1> <file2>'.",
"Commit the changes with a descriptive message.",
"Push your branch and create a pull request if needed."
],
"warnings": [
"This will overwrite the current working directory versions of the specified files.",
"Make sure to commit or stash any local changes to those files before running the command."
],
"tags": ["checkout", "restore", "file", "commit", "cherry-pick"],
"author": "mike-rambil",
"last_updated": "2024-06-10",
"links": [
{
"label": "Git Docs: git checkout",
"url": "https://git-scm.com/docs/git-checkout"
}
]
}
]