Última actividad 7 months ago

優化你的 Git 配置:添加快捷鍵,提升可讀性,確保個人資訊不入版控。

timmy revisó este gist 7 months ago. Ir a la revisión

Sin cambios

timmy revisó este gist 7 months ago. Ir a la revisión

3 files changed, 109 insertions

.gitconfig(archivo creado)

@@ -0,0 +1,93 @@
1 + # 引入本地個人設定,避免將個資存入版本控制
2 + [include]
3 + path = ~/.gitconfig.local
4 +
5 + # Git log 的預設顯示設定
6 + [log]
7 + decorate = short # 顯示簡短的 ref 名稱(例如 HEAD -> main)
8 + abbrevCommit = true # 顯示簡短的 commit hash(例如 1a2b3c4)
9 +
10 + # 常用 Git 指令的簡寫別名
11 + [alias]
12 + br = branch
13 + co = checkout
14 + ci = commit
15 + df = diff
16 + st = status
17 + g = grep -I
18 + lg = log -p
19 +
20 + # 顯示分支差異(未合併的 commit)
21 + ch = log --cherry --pretty=format:\"%C(auto)%h (%ar) %an: %s\" --date-order --reverse
22 +
23 + # 彩色圖形化 log(適合查看整體歷史)
24 + loq = log --graph --all --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(bold white)— %an%C(reset)%C(bold yellow)%d%C(reset)' --abbrev-commit --date=relative
25 +
26 + # 查找包含關鍵字的提交,並列出檔案異動
27 + find = log --pretty=\"format:%Cgreen%H %Cblue%s\" --name-status --grep
28 +
29 + # 分支相關設定
30 + [branch]
31 + autosetuprebase = always # 建立追蹤分支時預設使用 rebase 模式
32 +
33 + # 顏色顯示設定
34 + [color]
35 + ui = auto # 自動判斷是否啟用彩色輸出
36 +
37 + [color "branch"]
38 + current = yellow reverse # 當前分支:黃色反白
39 + local = yellow # 本地分支:黃色
40 + remote = green # 遠端分支:綠色
41 +
42 + [color "diff"]
43 + meta = yellow
44 + frag = magenta
45 + old = red
46 + new = green
47 +
48 + [color "status"]
49 + added = yellow
50 + changed = green
51 + untracked = cyan
52 +
53 + # 推送行為設定
54 + [push]
55 + default = simple # 只推送目前分支(最安全)
56 +
57 + # 自動記憶 conflict 解法,下次可自動套用
58 + [rerere]
59 + enabled = 1
60 +
61 + # 使用 Git 協定 v2(較快也支援更多功能)
62 + [protocol]
63 + version = 2
64 +
65 + # 新專案初始化時使用 main 作為預設分支
66 + [init]
67 + defaultBranch = main
68 +
69 + # 合併衝突顯示樣式
70 + [merge]
71 + conflictStyle = zdiff3 # 使用較清楚的 zdiff3 格式(需 Git >= 2.35)
72 +
73 + # GitHub CLI 整合登入憑證處理
74 + [github]
75 + user = your-github-username
76 +
77 + [credential "https://github.com"]
78 + helper =
79 + helper = !/usr/bin/gh auth git-credential
80 +
81 + [credential "https://gist.github.com"]
82 + helper =
83 + helper = !/usr/bin/gh auth git-credential
84 +
85 + # 使用 delta 作為美化 diff 的分頁器(需另行安裝 delta 工具)
86 + [core]
87 + pager = delta
88 +
89 + [interactive]
90 + diffFilter = delta --color-only
91 +
92 + [delta]
93 + navigate = true # 支援方向鍵/jk 捲動檢視 diff

.gitconfig.local(archivo creado)

@@ -0,0 +1,15 @@
1 + # 本地使用者設定(每台機器各自不同)
2 + [user]
3 + name = Your Name # 你的名稱,例如 Timmy
4 + email = your.name@example.com # 你的 Git email,例如 you@company.com
5 +
6 + # 若使用 GPG 簽名,可加上以下設定(可選)
7 + # [commit]
8 + # gpgsign = true # 啟用 GPG 簽章(需要先設定 GPG 金鑰)
9 +
10 + # 若你使用多帳號,也可以針對特定目錄設定不同 user(進階做法)
11 + # [includeIf "gitdir:~/projects/work/"]
12 + # path = ~/.gitconfig.work
13 + #
14 + # [includeIf "gitdir:~/projects/personal/"]
15 + # path = ~/.gitconfig.personal

git_tools_install.sh(archivo creado)

@@ -0,0 +1 @@
1 + brew install git-delta gh
Siguiente Anterior