跳转至

配置与工具

1 基础配置

# 用户名 & 邮箱
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"

# SSH 生成与绑定
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
cat ~/.ssh/id_rsa.pub
eval `ssh-agent -s`

# 代理设置
git config --global https.proxy http://127.0.0.1:12333
git config --global https.proxy https://127.0.0.1:12333

# 远程仓库相关
git remote -v
git remote set-url origin git@gitea.beyondxin.top:BeyondXin/MyNote.git
git remote add origin git@gitea.beyondxin.top:BeyondXin/MyNote.git

2 仓库结构

_空目录保留

Git 不跟踪空目录。如项目必须保留某些目录,可在目录下添加占位文件: .gitkeep

_.gitignore 规则

  • / 相对仓库根目录
    • 通配符
  • ! 放行(取反)
# 忽略全部
/*

# 放行指定目录及内容
!Stc1/
!Stc1/*
!Stc2/
!Stc2/*

# 忽略临时文件
*.log
*.tmp

# 忽略编译产物
build/
dist/

Modules

git submodule update --init --remote --recursive

3 Hooks

Git Hooks 是 Git 在特定操作(commit / push 等)前后自动执行的脚本机制,可用于自动校验、通知、代码检查等。使用方式:增加对应脚本放到 .git/hooks

例:每次push的时候推送到飞书群聊 .git/hooks/pre-push

#!/bin/sh
export LC_ALL=zh_CN.GB2312
export LANG=zh_CN.GB2312
hash=$(git rev-parse HEAD)
name=$(git log -1 --pretty=format:'%an')
content=$(git log -1 --pretty=format:'%s')
json_data=$(printf '{"msg_type":"text","content":{"text":"{repository: PlatformConfig, name: %s, content: %s, Link: http://172.16.44.197:8081/q/status:open+-is:wip}"}}' "$name" "$content")
echo "$json_data"
curl -X POST -H "Content-Type: application/json" -d "$json_data" https://open.feishu.cn/open-apis/bot/v2/hook/xxxx

说明:

  • pre-commit → 提交前执行
  • pre-push → 推送前执行
  • post-commit → 提交后执行

常见用途:

  • 提交规范校验
  • 自动格式化
  • CI 触发
  • 通知推送

4 TortoiseGit 使用 openssh

  • 默认使用:TortoiseGitPlink
  • 推荐改为:OpenSSH(统一和 Git Bash)

    与 Git Bash 共用同一套 SSH 配置和密钥,避免多套 SSH 工具带来的配置冲突和认证问题。

配置步骤:

  1. 右键 → TortoiseGit -> 设置
  2. 进入 网络
  3. 修改 SSH 客户端为: C:\Program Files\Git\usr\bin\ssh.exe