Git 代理配置

使用代理的动机 内网或跨境访问 Git 仓库时,常会遇到延迟高、连接失败、TLS 握手超时等问题。通过为 Git 配置代理,可以复用团队的跳板机、单机 Clash、SS/SSR、V2Ray、企业 HTTP Proxy 等网络能力,加速 git clone、git fetch 等操作。 快速启用 HTTP/HTTPS 代理 最常见的做法是直接写入 Git 配置: # 全局配置(~/.gitconfig) git config --global http.proxy http://127.0.0.1:7890 git config --global https.proxy http://127.0.0.1:7890 如果是单个仓库,去掉 --global,在项目根目录执行即可: # 仅对当前仓库生效 git config http.proxy http://127.0.0.1:7890 git config https.proxy http://127.0.0.1:7890 可借助 git config --global -l | grep proxy 快速确认配置。 配置 SOCKS 代理 与 HTTP/HTTPS 配置类似,只是需要显式声明 socks5: # Clash / V2Ray 等提供 SOCKS 端口时 port=7891 git config --global http.proxy socks5://127.0.0.1:$port git config --global https.proxy socks5://127.0.0.1:$port 部分代理工具会同时提供 HTTP 和 SOCKS 端口,可根据需要选择。 ...

2022年4月19日 · 1 分钟 · 207 字

Git协作常用基础操作(2)

Rebase 与历史整理 交互式 rebase 用于梳理一组提交的顺序、合并或拆分: git rebase -i HEAD~5 常见指令含义: pick:保留提交 reword:修改提交说明 squash:将多条提交压缩为一条 edit:暂停以修改内容 解决冲突后继续 git status # 查看冲突 git add <resolved-file> git rebase --continue git rebase --abort # 放弃本次 rebase 在公共分支谨慎使用 对已推送的分支执行 rebase 会改写历史。如果需要,对团队成员提前同步,并使用 git push --force-with-lease,减少误覆盖他人提交的风险。 变基 + 合并的组合拳 git pull --rebase:获取远程提交并把本地提交“平铺”在其后,减少无意义的合并节点。 git rebase origin/master:在功能分支上更新 master 的最新代码。 git merge --no-ff:保留合并节点,便于追踪特性分支的历史。 Bisect:二分定位缺陷 当某个时间段引入了 bug,可用 git bisect 快速锁定问题提交。 git bisect start git bisect bad HEAD # 标记当前为坏提交 git bisect good v1.1.0 # 标记已知正常的版本 随后按提示运行测试: ...

2022年4月14日 · 2 分钟 · 276 字

Git协作常用基础操作(1)

配置与巡检 新环境初次使用前,建议逐层检查配置来源,避免混入旧账户信息: git config --system --list # 系统级配置 git config --global --list # 当前用户配置 git config --local --list # 仓库内配置 git config --list --show-origin # 查看值来源 设置签名信息与常用别名: git config --global user.name "Team Member" git config --global user.email "[email protected]" git config --global core.editor "code --wait" git config --global alias.st status .gitignore_global 用于跨项目忽略临时文件: git config --global core.excludesfile ~/.gitignore_global echo '.DS_Store' >> ~/.gitignore_global 工作区到提交的路径 掌握工作区 → 暂存区 → 本地仓库的跃迁方式: git status -sb # 简明状态 git add <file> # 添加单个文件 git add . # 批量添加 git restore --staged <file> # 从暂存区撤回 git restore <file> # 丢弃工作区修改 commit规范 Conventional Commits 风格 ...

2022年4月13日 · 2 分钟 · 383 字