## Git 是什么 Git是一个开源的分布式版本控制系统,主要用于软件开发中的代码管理。它允许多个开发者在各自的分支上工作,独立提交更改,然后合并这些更改,从而促进团队协作和项目进度的跟踪。Git的设计强调性能、灵活性和安全性,使其成为当今广泛使用的版本控制系统之一。 ## 提交规范 ```Plain <type>(<scope>): <summary> │ │ │ │ │ └─> commit 简短描述 │ │ │ └─> 可选,用于说明 commit 影响的范围,比如数据层、控制层、视图层等等 │ └─> Commit 类别: feat|fix|docs|refactor|perf|test|build|ci ``` `<type>` 是用于说明 commit 的类别,可以参考使用下面这些标示 - **build**: 变更影响的是构建系统或者外部依赖 (如: gulp, npm) - **ci**: 修改了 CI 配置文件或脚本 (如: Github Action, Travis) - **chore**: 【重要】 变更不影响源代码或测试(如更新了辅助工具、库等) - **docs**: 只修改了文档 - **feat**: 【重要】 一个新特性 - **fix**: 【重要】 修复了一个 Bug - **perf**: 增强性能的代码变更 - **refactor**: 并非修复 Bug 或添加新特性的代码变更 - **revert**: 回退代码 - **style**: 变更不影响一些有意义的代码 (如: 删除空格、格式化代码、添加分号等) - **test**: 添加测试代码或修正已有的测试 ## 配置 ```Shell # 查看配置 $ git config --list # 在文本编辑器中编辑全局配置文件 $ git config --global --edit # 设置提交名称和邮箱 $ git config --global user.name <name> $ git config --global user.email <email> # 删除全局设置 $ git config --global --unset <entry-name> ``` ## 创建一个新仓库 ```Shell $ git clone [email protected]:catcto/test.git $ cd test $ git switch -c main $ touch README.md $ git add README.md $ git commit -m "add README" $ git push -u origin main ``` ## 推送现有文件夹 ```Shell $ cd existing_folder $ git init --initial-branch=main $ git remote add origin [email protected]:catcto/test.git $ git add . $ git commit -m "first commit" $ git push -u origin main ``` ## 推送现有的 git 仓库 ```Shell $ cd existing_repo $ git remote rename origin old-origin $ git remote add origin [email protected]:catcto/test.git $ git push -u origin --all $ git push -u origin --tags ``` ## 重置远程 ```Shell # 查看提交历史 $ git log $ git show <HEAD> # 重置到某个 HEAD 并提交到远程 master 分支 $ git reset --hard <HEAD> $ git push origin HEAD --force ``` ## 配置 http 和 socks 代理 ```Shell # 查看代理 $ git config --global http.proxy $ git config --global https.proxy $ git config --global socks.proxy # 设置代理 # 适用于 privoxy 将 socks 协议转为 http 协议的 http 端口 $ git config --global http.proxy http://127.0.0.1:1080 $ git config --global https.proxy http://127.0.0.1:1080 $ git config --global socks.proxy 127.0.0.1:1080 # 取消代理 $ git config --global --unset http.proxy $ git config --global --unset https.proxy $ git config --global --unset socks.proxy # 只对 github.com 设置代理 $ git config --global http.https://github.com.proxy socks5://127.0.0.1:1080 $ git config --global https.https://github.com.proxy socks5://127.0.0.1:1080 # 取消 github.com 代理 $ git config --global --unset http.https://github.com.proxy $ git config --global --unset https.https://github.com.proxy ``` ## 配置 ssh 协议代理 对于使用 git@ 协议的,可以配置 socks5 代理, macOS 系统编辑 `~/.ssh/config` 文件,添加这几行 ```Plain Host github.com ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p ``` ## github host ``` #Github Hosts Start #Update Time: 2026-03-25 #Project Address: https://github.com/maxiaof/github-hosts #Update URL: https://raw.githubusercontent.com/maxiaof/github-hosts/master/hosts 140.82.114.25 alive.github.com 140.82.113.26 live.github.com 185.199.108.154 github.githubassets.com 140.82.114.22 central.github.com 185.199.108.133 desktop.githubusercontent.com 185.199.110.133 camo.githubusercontent.com 185.199.108.133 github.map.fastly.net 146.75.121.194 github.global.ssl.fastly.net 140.82.121.4 gist.github.com 185.199.109.153 github.io 140.82.121.4 github.com 192.0.66.2 github.blog 140.82.121.6 api.github.com 185.199.108.133 raw.githubusercontent.com 185.199.108.133 user-images.githubusercontent.com 185.199.109.133 favicons.githubusercontent.com 185.199.110.133 avatars5.githubusercontent.com 185.199.109.133 avatars4.githubusercontent.com 185.199.108.133 avatars3.githubusercontent.com 185.199.111.133 avatars2.githubusercontent.com 185.199.109.133 avatars1.githubusercontent.com 185.199.111.133 avatars0.githubusercontent.com 185.199.110.133 avatars.githubusercontent.com 140.82.121.9 codeload.github.com 3.5.28.32 github-cloud.s3.amazonaws.com 52.217.112.89 github-com.s3.amazonaws.com 16.15.192.252 github-production-release-asset-2e65be.s3.amazonaws.com 52.217.140.1 github-production-user-asset-6210df.s3.amazonaws.com 16.15.199.8 github-production-repository-file-5c1aeb.s3.amazonaws.com 185.199.109.153 githubstatus.com 140.82.112.17 github.community 51.137.3.17 github.dev 140.82.114.21 collector.github.com 13.107.42.16 pipelines.actions.githubusercontent.com 185.199.111.133 media.githubusercontent.com 185.199.110.133 cloud.githubusercontent.com 185.199.109.133 objects.githubusercontent.com #Github Hosts End ``` ## 参考 - https://git-scm.com/book/zh/v2 - https://github.com/angular/angular/blob/main/CONTRIBUTING.md