diff --git a/contents/apply-diff-file.md b/contents/apply-diff-file.md index 5191533..db09bec 100644 --- a/contents/apply-diff-file.md +++ b/contents/apply-diff-file.md @@ -16,11 +16,13 @@ git apply changes.diff - **Apply a diff file of uncommitted changes.** ```sh -git apply changes.diff``` +git apply changes.diff + ``` - **Show what would change if the diff were applied.** ```sh -git apply --stat changes.diff``` +git apply --stat changes.diff + ``` #### Steps diff --git a/contents/apply-patch-with-commit-metadata.md b/contents/apply-patch-with-commit-metadata.md index 8103b8a..bb91577 100644 --- a/contents/apply-patch-with-commit-metadata.md +++ b/contents/apply-patch-with-commit-metadata.md @@ -16,11 +16,13 @@ git am my-changes.patch - **Apply a patch file and preserve commit info.** ```sh -git am my-changes.patch``` +git am my-changes.patch + ``` - **Apply a patch and add a Signed-off-by line.** ```sh -git am --signoff my-changes.patch``` +git am --signoff my-changes.patch + ``` #### Steps diff --git a/contents/check-existing-worktrees.md b/contents/check-existing-worktrees.md index d34e846..d49d718 100644 --- a/contents/check-existing-worktrees.md +++ b/contents/check-existing-worktrees.md @@ -14,11 +14,13 @@ git worktree list - **List all active worktrees.** ```sh -git worktree list``` +git worktree list + ``` - **List worktrees in a machine-readable format.** ```sh -git worktree list --porcelain``` +git worktree list --porcelain + ``` #### Steps diff --git a/contents/create-a-new-worktree.md b/contents/create-a-new-worktree.md index 6b338d6..d375232 100644 --- a/contents/create-a-new-worktree.md +++ b/contents/create-a-new-worktree.md @@ -16,11 +16,13 @@ git worktree add - **Create a new worktree for the feature branch.** ```sh -git worktree add ../feature-branch feature``` +git worktree add ../feature-branch feature + ``` - **Create a worktree for a hotfix branch.** ```sh -git worktree add ../hotfix hotfix-branch``` +git worktree add ../hotfix hotfix-branch + ``` #### Steps diff --git a/contents/create-patch-from-last-commit-s.md b/contents/create-patch-from-last-commit-s.md index 0fd50df..33b0b05 100644 --- a/contents/create-patch-from-last-commit-s.md +++ b/contents/create-patch-from-last-commit-s.md @@ -14,19 +14,23 @@ git format-patch HEAD~1 - **Create a .patch file for the last commit.** ```sh -git format-patch HEAD~1``` +git format-patch HEAD~1 + ``` - **Create a single patch file for all commits on top of main.** ```sh -git format-patch origin/main..HEAD --stdout > my-changes.patch``` +git format-patch origin/main..HEAD --stdout > my-changes.patch + ``` - **Create patch files for the last two commits.** ```sh -git format-patch -2``` +git format-patch -2 + ``` - **Create patch files for all commits since main.** ```sh -git format-patch -2 origin/main..HEAD``` +git format-patch -2 origin/main..HEAD + ``` #### Steps diff --git a/contents/create-patch-from-uncommitted-changes.md b/contents/create-patch-from-uncommitted-changes.md index 1cc9527..f2effd8 100644 --- a/contents/create-patch-from-uncommitted-changes.md +++ b/contents/create-patch-from-uncommitted-changes.md @@ -16,11 +16,13 @@ git diff > changes.diff - **Create a diff file of uncommitted changes.** ```sh -git diff > changes.diff``` +git diff > changes.diff + ``` - **Create a diff file for the last commit.** ```sh -git diff HEAD~1 > last-commit.diff``` +git diff HEAD~1 > last-commit.diff + ``` #### Steps diff --git a/contents/delete-local-branches-whose-remote-is-gone-bash.md b/contents/delete-local-branches-whose-remote-is-gone-bash.md index b0d7555..4a989db 100644 --- a/contents/delete-local-branches-whose-remote-is-gone-bash.md +++ b/contents/delete-local-branches-whose-remote-is-gone-bash.md @@ -18,11 +18,13 @@ git fetch -p && git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | - **Delete all local branches whose remote is gone.** ```sh -git fetch -p && git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | xargs -r git branch -d``` +git fetch -p && git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | xargs -r git branch -d + ``` - **Delete only feature branches whose remote is gone.** ```sh -git fetch -p && git branch -vv | grep '\[origin/feature: gone\]' | awk '{print $1}' | xargs -r git branch -d``` +git fetch -p && git branch -vv | grep '\[origin/feature: gone\]' | awk '{print $1}' | xargs -r git branch -d + ``` #### Steps diff --git a/contents/delete-local-branches-whose-remote-is-gone-powershell.md b/contents/delete-local-branches-whose-remote-is-gone-powershell.md index 63461cf..4db9ba5 100644 --- a/contents/delete-local-branches-whose-remote-is-gone-powershell.md +++ b/contents/delete-local-branches-whose-remote-is-gone-powershell.md @@ -22,12 +22,14 @@ git branch -vv | ForEach-Object { if ($_ -match '\[.*: gone\]') { $parts = $_.Tr ```sh git fetch -p -git branch -vv | ForEach-Object { if ($_ -match '[.*: gone]') { $parts = $_.Trim() -split '\s+'; $branch = $parts[0]; if ($branch -ne '') { git branch -d $branch } } }``` +git branch -vv | ForEach-Object { if ($_ -match '[.*: gone]') { $parts = $_.Trim() -split '\s+'; $branch = $parts[0]; if ($branch -ne '') { git branch -d $branch } } } + ``` - **Delete only feature branches whose remote is gone.** ```sh git fetch -p -git branch -vv | ForEach-Object { if ($_ -match '[origin/feature: gone]') { $parts = $_.Trim() -split 's+'; $branch = $parts[0]; if ($branch -ne '') { git branch -d $branch } } }``` +git branch -vv | ForEach-Object { if ($_ -match '[origin/feature: gone]') { $parts = $_.Trim() -split 's+'; $branch = $parts[0]; if ($branch -ne '') { git branch -d $branch } } } + ``` #### Steps diff --git a/contents/git-clean-remove-untracked-files-and-directories.md b/contents/git-clean-remove-untracked-files-and-directories.md index ad0192f..0cb75bd 100644 --- a/contents/git-clean-remove-untracked-files-and-directories.md +++ b/contents/git-clean-remove-untracked-files-and-directories.md @@ -27,23 +27,28 @@ git clean - **Preview what will be deleted (dry run).** ```sh -git clean -n -d``` +git clean -n -d + ``` - **Delete all untracked files.** ```sh -git clean -f``` +git clean -f + ``` - **Delete all untracked files and directories.** ```sh -git clean -f -d``` +git clean -f -d + ``` - **Interactive mode for selective deletion.** ```sh -git clean -i``` +git clean -i + ``` - **Delete untracked and ignored files.** ```sh -git clean -f -x``` +git clean -f -x + ``` #### Steps diff --git a/contents/git-clone-mirror-repository.md b/contents/git-clone-mirror-repository.md index b1b79a6..1e5f2df 100644 --- a/contents/git-clone-mirror-repository.md +++ b/contents/git-clone-mirror-repository.md @@ -18,11 +18,13 @@ git clone --mirror https://github.com/example/repo.git - **Create a full backup or migration of a repository.** ```sh -git clone --mirror https://github.com/example/repo.git``` +git clone --mirror https://github.com/example/repo.git + ``` - **Mirror-clone a private repo using SSH.** ```sh -git clone --mirror git@github.com:org/repo.git``` +git clone --mirror git@github.com:org/repo.git + ``` #### Steps diff --git a/contents/git-init-bare.md b/contents/git-init-bare.md index 4f2993d..78b82a4 100644 --- a/contents/git-init-bare.md +++ b/contents/git-init-bare.md @@ -16,11 +16,13 @@ git init --bare my-repo.git - **Create a bare repository for collaboration.** ```sh -git init --bare my-repo.git``` +git init --bare my-repo.git + ``` - **Initialize a bare repo in a custom directory for server hosting.** ```sh -git init --bare /srv/git/project.git``` +git init --bare /srv/git/project.git + ``` #### Steps diff --git a/contents/git-maintenance-start.md b/contents/git-maintenance-start.md index 6467b8d..16837b2 100644 --- a/contents/git-maintenance-start.md +++ b/contents/git-maintenance-start.md @@ -18,13 +18,15 @@ git maintenance start - **Enable background maintenance for your repository.** ```sh -git maintenance start -``` + +git maintenance start + ``` - **Run maintenance tasks every hour for more active repos.** ```sh -git maintenance start --schedule=hourly -``` +git maintenance start --schedule=hourly + ``` + #### Steps diff --git a/contents/git-replace-old-commit-new-commit.md b/contents/git-replace-old-commit-new-commit.md index 0fa34be..58f8008 100644 --- a/contents/git-replace-old-commit-new-commit.md +++ b/contents/git-replace-old-commit-new-commit.md @@ -16,11 +16,13 @@ git replace abc123 def456 - **Temporarily replace commit abc123 with def456.** ```sh -git replace abc123 def456``` +git replace abc123 def456 + ``` - **Graft a new parent onto a commit for testing history changes.** ```sh -git replace --graft HEAD~2 HEAD``` +git replace --graft HEAD~2 HEAD + ``` #### Steps diff --git a/contents/git-request-pull.md b/contents/git-request-pull.md index 840c1c7..fb62eed 100644 --- a/contents/git-request-pull.md +++ b/contents/git-request-pull.md @@ -39,15 +39,18 @@ for you to fetch changes up to 89abcde... (feature-branch): file1.txt | 10 ++++++++++ file2.js | 5 +++++ 2 files changed, 15 insertions(+) -``` + + ``` - **Generate a pull request message from v1.0 to v1.1.** ```sh -git request-pull v1.0 https://github.com/example/repo.git v1.1``` +git request-pull v1.0 https://github.com/example/repo.git v1.1 + ``` - **Request a pull for a feature branch based on main.** ```sh -git request-pull main https://github.com/example/repo.git feature-branch``` +git request-pull main https://github.com/example/repo.git feature-branch + ``` #### Steps diff --git a/contents/how-to-use-git-push-force-with-lease-safely.md b/contents/how-to-use-git-push-force-with-lease-safely.md index 3a6d122..e85ec46 100644 --- a/contents/how-to-use-git-push-force-with-lease-safely.md +++ b/contents/how-to-use-git-push-force-with-lease-safely.md @@ -18,11 +18,13 @@ git push --force-with-lease - **Safely force-push your changes.** ```sh -git push --force-with-lease``` +git push --force-with-lease + ``` - **Force-push a specific branch with lease protection.** ```sh -git push --force-with-lease origin feature-branch``` +git push --force-with-lease origin feature-branch + ``` #### Steps diff --git a/contents/pull-changes-of-specific-files-from-a-commit.md b/contents/pull-changes-of-specific-files-from-a-commit.md index 7c166d0..9869e00 100644 --- a/contents/pull-changes-of-specific-files-from-a-commit.md +++ b/contents/pull-changes-of-specific-files-from-a-commit.md @@ -18,17 +18,20 @@ git checkout -- - **Restore file1.txt and file2.txt from the specified commit.** ```sh -git checkout e8ab7f64fdfcc7bdaaed8d96c0ac26dce035663f -- path/to/file1.txt path/to/file2.txt``` +git checkout e8ab7f64fdfcc7bdaaed8d96c0ac26dce035663f -- path/to/file1.txt path/to/file2.txt + ``` - **Stage, commit, and push the restored files to a new branch.** ```sh git add path/to/file1.txt path/to/file2.txt git commit -m "Pulled changes for file1.txt and file2.txt from commit e8ab7f64" -git push origin revert/productionOrder``` +git push origin revert/productionOrder + ``` - **Restore files using the newer 'git restore' command.** ```sh -git restore --source e8ab7f64fdfcc7bdaaed8d96c0ac26dce035663f path/to/file1.txt path/to/file2.txt``` +git restore --source e8ab7f64fdfcc7bdaaed8d96c0ac26dce035663f path/to/file1.txt path/to/file2.txt + ``` #### Steps diff --git a/contents/remove-a-worktree.md b/contents/remove-a-worktree.md index 455c51c..23fae10 100644 --- a/contents/remove-a-worktree.md +++ b/contents/remove-a-worktree.md @@ -16,11 +16,13 @@ git worktree remove - **Detach a worktree without deleting the files.** ```sh -git worktree remove ../feature-branch``` +git worktree remove ../feature-branch + ``` - **Remove a hotfix worktree.** ```sh -git worktree remove ../hotfix``` +git worktree remove ../hotfix + ``` #### Steps diff --git a/contents/see-who-last-modified-each-line-blame.md b/contents/see-who-last-modified-each-line-blame.md index 292a720..23620ee 100644 --- a/contents/see-who-last-modified-each-line-blame.md +++ b/contents/see-who-last-modified-each-line-blame.md @@ -16,11 +16,13 @@ git blame filename.txt - **Show the last commit that changed each line of the file.** ```sh -git blame filename.txt``` +git blame filename.txt + ``` - **Blame only lines 10 to 20 of a file.** ```sh -git blame -L 10,20 filename.txt``` +git blame -L 10,20 filename.txt + ``` #### Steps diff --git a/contents/show-commit-history-of-a-specific-file.md b/contents/show-commit-history-of-a-specific-file.md index ff66b3e..a5f4e7d 100644 --- a/contents/show-commit-history-of-a-specific-file.md +++ b/contents/show-commit-history-of-a-specific-file.md @@ -14,11 +14,13 @@ git log --oneline -- filename.txt - **List all commits that modified `filename.txt`.** ```sh -git log --oneline -- filename.txt``` +git log --oneline -- filename.txt + ``` - **Show commit history for a different file.** ```sh -git log --oneline -- path/to/anotherfile.js``` +git log --oneline -- path/to/anotherfile.js + ``` #### Steps diff --git a/contents/show-commit-history-with-author-and-date.md b/contents/show-commit-history-with-author-and-date.md index 969679f..660dac5 100644 --- a/contents/show-commit-history-with-author-and-date.md +++ b/contents/show-commit-history-with-author-and-date.md @@ -16,11 +16,13 @@ git log --pretty=format:"%h - %an, %ar : %s" -- filename.txt - **Display commit hash, author, relative date, and commit message.** ```sh -git log --pretty=format:"%h - %an, %ar : %s" -- filename.txt``` +git log --pretty=format:"%h - %an, %ar : %s" -- filename.txt + ``` - **Show commit hash, short date, author, and message.** ```sh -git log --pretty=format:'%h | %ad | %an | %s' --date=short -- filename.txt``` +git log --pretty=format:'%h | %ad | %an | %s' --date=short -- filename.txt + ``` #### Steps diff --git a/contents/show-detailed-commit-history-with-changes.md b/contents/show-detailed-commit-history-with-changes.md index 106099c..28edacf 100644 --- a/contents/show-detailed-commit-history-with-changes.md +++ b/contents/show-detailed-commit-history-with-changes.md @@ -16,11 +16,13 @@ git log -p -- filename.txt - **Show each commit and the actual changes made to `filename.txt`.** ```sh -git log -p -- filename.txt``` +git log -p -- filename.txt + ``` - **Show the last two commits and their changes for a file.** ```sh -git log -p -2 -- filename.txt``` +git log -p -2 -- filename.txt + ``` #### Steps diff --git a/contents/switch-between-worktrees.md b/contents/switch-between-worktrees.md index bc35551..6b4e597 100644 --- a/contents/switch-between-worktrees.md +++ b/contents/switch-between-worktrees.md @@ -14,11 +14,13 @@ - **Switch to the worktree directory.** ```sh -cd ../feature-branch``` +cd ../feature-branch + ``` - **Switch to a hotfix worktree.** ```sh -cd ../hotfix``` +cd ../hotfix + ``` #### Steps diff --git a/contents/use-worktrees-for-temporary-fixes.md b/contents/use-worktrees-for-temporary-fixes.md index e66a38e..54c271f 100644 --- a/contents/use-worktrees-for-temporary-fixes.md +++ b/contents/use-worktrees-for-temporary-fixes.md @@ -16,11 +16,13 @@ git worktree add ../hotfix hotfix-branch - **Quickly apply a fix on another branch without leaving your main branch.** ```sh -git worktree add ../hotfix hotfix-branch``` +git worktree add ../hotfix hotfix-branch + ``` - **Create a worktree for a bugfix branch.** ```sh -git worktree add ../bugfix bugfix-branch``` +git worktree add ../bugfix bugfix-branch + ``` #### Steps diff --git a/contents/view-and-clean-up-local-git-branches-bash.md b/contents/view-and-clean-up-local-git-branches-bash.md index fb3897f..1b4a812 100644 --- a/contents/view-and-clean-up-local-git-branches-bash.md +++ b/contents/view-and-clean-up-local-git-branches-bash.md @@ -13,15 +13,18 @@ - **List local branches without a remote connection.** ```sh -git branch -vv | grep -E '^\s*\S+\s+[^\[]+$'``` +git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' + ``` - **Delete local branches without remote tracking.** ```sh -git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' | awk '{print $1}' | xargs git branch -D``` +git branch -vv | grep -E '^\s*\S+\s+[^\[]+$' | awk '{print $1}' | xargs git branch -D + ``` - **List branches whose remote is gone.** ```sh -git branch -vv | grep 'gone'``` +git branch -vv | grep 'gone' + ``` #### Steps diff --git a/contents/view-and-clean-up-local-git-branches-powershell.md b/contents/view-and-clean-up-local-git-branches-powershell.md index 9b8c52e..e3f8f1e 100644 --- a/contents/view-and-clean-up-local-git-branches-powershell.md +++ b/contents/view-and-clean-up-local-git-branches-powershell.md @@ -13,15 +13,18 @@ - **List local branches without a remote connection.** ```sh -git branch -vv | Select-String -NotMatch "origin/"``` +git branch -vv | Select-String -NotMatch "origin/" + ``` - **Delete local branches without remote tracking.** ```sh -git branch -vv | Select-String -NotMatch "origin/" | ForEach-Object { $branch = ($_ -split "\s+")[1]; git branch -D $branch }``` +git branch -vv | Select-String -NotMatch "origin/" | ForEach-Object { $branch = ($_ -split "\s+")[1]; git branch -D $branch } + ``` - **List branches whose remote is gone.** ```sh -git branch -vv | Select-String 'gone'``` +git branch -vv | Select-String 'gone' + ``` #### Steps diff --git a/scripts/generate-readme.js b/scripts/generate-readme.js index f8870f5..dec10a3 100644 --- a/scripts/generate-readme.js +++ b/scripts/generate-readme.js @@ -97,7 +97,9 @@ function renderExamples(examples) { if (!examples || !examples.length) return ''; let out = ''; examples.forEach((ex) => { - out += `- **${ex.description || ''}** \n\n \`\`\`sh\n${ex.code}\`\`\`\n`; + out += `- **${ex.description || ''}** \n\n \`\`\`sh\n${ + ex.code + } \n \`\`\`\n`; }); return renderSection('Examples', out); }