0b04a4de50
Leave global name/email empty with useConfigOnly so unmatched repos cannot commit. Personal identity applies under ~/.dotfile, ~/code, and ~/.pouch; work identity stays in local ~/.gitconfig.work for ~/workrepo.
147 lines
5.0 KiB
INI
147 lines
5.0 KiB
INI
# 不设全局 user.name / user.email,避免未匹配目录误用身份。
|
||
# useConfigOnly(Git 2.8+):未配置时拒绝 commit,而不是猜系统用户名。
|
||
[user]
|
||
useConfigOnly = true
|
||
[core]
|
||
autocrlf = input
|
||
quotepath = false
|
||
editor = vim
|
||
excludesfile = ~/.dotfile/git/.gitignore
|
||
[init]
|
||
defaultBranch = main
|
||
[tag]
|
||
sort = version:refname
|
||
[column]
|
||
ui = auto
|
||
[color]
|
||
status = auto
|
||
diff = auto
|
||
branch = auto
|
||
interactive = auto
|
||
grep = auto
|
||
ui = auto
|
||
[push]
|
||
#default = current
|
||
default = simple
|
||
autoSetupRemote = true
|
||
followTags = true
|
||
[fetch]
|
||
prune = true
|
||
pruneTags = true
|
||
all = true
|
||
[pull]
|
||
rebase = false
|
||
[diff]
|
||
algorithm = histogram
|
||
colorMoved = plain
|
||
mnemonicPrefix = true
|
||
renames = true
|
||
[difftool "nvimdiff"]
|
||
cmd = nvim -d \"$LOCAL\" \"$REMOTE\"
|
||
[merge]
|
||
tool = nvimdiff
|
||
[mergetool "nvimdiff"]
|
||
cmd = nvim -d \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
|
||
trustExitCode = true
|
||
# 按仓库目录套身份。个人身份在 git/.gitconfig.personal;公司邮箱只放本机 ~/.gitconfig.work。
|
||
# include 目标文件必须存在,否则该目录下 git 命令会直接 fatal。
|
||
[includeIf "gitdir:~/.dotfile/"]
|
||
path = ~/.dotfile/git/.gitconfig.personal
|
||
[includeIf "gitdir:~/code/"]
|
||
path = ~/.dotfile/git/.gitconfig.personal
|
||
[includeIf "gitdir:~/.pouch/"]
|
||
path = ~/.dotfile/git/.gitconfig.personal
|
||
[includeIf "gitdir:~/workrepo/"]
|
||
path = ~/.gitconfig.work
|
||
[rebase]
|
||
autoSquash = true
|
||
autoStash = true
|
||
updateRefs = true
|
||
[commit]
|
||
verbose = true
|
||
[rerere]
|
||
enabled = true
|
||
autoupdate = true
|
||
[help]
|
||
# 旧版 Git 仅支持数字(0=仅提示不执行)。Git 2.36+ 见 .gitconfig.darwin / .gitconfig.linux 可改为 prompt
|
||
autocorrect = 0
|
||
[branch]
|
||
autoSetupMerge = always
|
||
sort = -committerdate
|
||
[alias]
|
||
au = add -u
|
||
co = checkout
|
||
cm = "!f() { if [[ -z \"$1\" ]]; then git commit; else git commit -m \"$*\"; fi; }; f"
|
||
st = status
|
||
ap = add -p
|
||
br = branch
|
||
ba = branch -a
|
||
bm = branch --merged
|
||
bn = branch --no-merged
|
||
pu = "!git pull origin $(git rev-parse --abbrev-ref HEAD)"
|
||
pt = push origin --tags
|
||
ph = push origin HEAD
|
||
pht = push origin --tags
|
||
# 把当前分支合进目标分支后回到当前分支;目标已被其它 worktree 占用时在那边 merge
|
||
merge2 = !$HOME/.dotfile/git/git-merge2.sh
|
||
bg = "!f() { git branch | grep $1; }; f"
|
||
delbr = "!f(){ git branch -D $(git branch | grep \"\b$1\"); };f"
|
||
can = commit --amend --no-edit
|
||
cleanbr = "!git branch --merged master | grep -v '\\*\\|master\\|main' | xargs -n 1 git branch -d"
|
||
# list files which have changed since REVIEW_BASE
|
||
# (REVIEW_BASE defaults to 'master' in my zshrc)
|
||
files = !git diff --name-only $(git merge-base HEAD \"$REVIEW_BASE\")
|
||
rmsubmodule = "!f(){ git submodule deinit -f \"$1\"; git rm -f \"$1\"; git commit -m \"Removed submodule $1\"; };f"
|
||
|
||
# Same as above, but with a diff stat instead of just names
|
||
# (better for interactive use)
|
||
stat = !git diff --stat $(git merge-base HEAD \"$REVIEW_BASE\")
|
||
# Open all files changed since REVIEW_BASE in Vim tabs
|
||
# Then, run fugitive's :Gdiff in each tab, and finally
|
||
# tell vim-gitgutter to show +/- for changes since REVIEW_BASE
|
||
review = !vim -p $(git files) +\"tabdo Gdiffsplit $REVIEW_BASE\" +\"let g:gitgutter_diff_base = '$REVIEW_BASE'\"
|
||
|
||
# Same as the above, except specify names of files as arguments,
|
||
# instead of opening all files:
|
||
# git reviewone foo.js bar.js
|
||
reviewone = !vim -p +\"tabdo Gdiff $REVIEW_BASE\" +\"let g:gitgutter_diff_base = '$REVIEW_BASE'\"
|
||
#git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Laily'; GIT_AUTHOR_EMAIL='i@laily.net'; GIT_COMMITTER_NAME='Laily'; GIT_COMMITTER_EMAIL='i@laily.net';" HEAD
|
||
|
||
# worktree
|
||
# git wt add <路径> <分支名>
|
||
# git wt add -b <新分支名> <路径> [基分支名]
|
||
wt="worktree"
|
||
#wta="worktree add"
|
||
#wtb="worktree add -b"
|
||
wtr="worktree remove"
|
||
wtl="worktree list"
|
||
wtp="worktree prune"
|
||
# 基于分支创建新分支+worktree
|
||
# git wtb <分支名> [<基分支名|当前分支>]
|
||
wtb = "!f(){ local base_branch=${2:-HEAD}; local clean_name=$(echo \"$1\" | sed \"s/\\//_/g\"); git worktree add -b \"$1\" \"../$clean_name\" $base_branch; }; f"
|
||
# 基于指定分支+worktree
|
||
# git wta <分支名>
|
||
wta = "!f(){ local base_branch=${1:-HEAD}; local clean_name=$(echo \"$1\" | sed \"s/\\//_/g\"); git worktree add \"../$clean_name\" $base_branch; }; f"
|
||
[protocol "file"]
|
||
allow = always
|
||
|
||
# https://hyperzsb.io/posts/git-ssl-error/
|
||
[filter "lfs"]
|
||
process = git-lfs filter-process
|
||
required = true
|
||
clean = git-lfs clean -- %f
|
||
smudge = git-lfs smudge -- %f
|
||
[http]
|
||
sslVerify = false
|
||
|
||
# 凭据:统一 wrapper,不依赖 includeIf ondarwin/onlinux(需 Git 2.36+)
|
||
# 低版本 Git 也会加载本节;回退为 git-credential-store(~/.git-credentials)
|
||
[credential]
|
||
helper = !$HOME/.dotfile/git/git-credential.sh
|
||
|
||
# 以下 includeIf 需 Git 2.36+;仅用于其它平台差异配置(若有)
|
||
[includeIf "ondarwin"]
|
||
path = ~/.dotfile/git/.gitconfig.darwin
|
||
[includeIf "onlinux"]
|
||
path = ~/.dotfile/git/.gitconfig.linux
|