Git 下载 、安装、规范

1、下载

官网地址:https://git-scm.com/download

2、安装

  1. 打开.exe安装程序, 点击next

  2. 选择安装路径(根据个人习惯选择)

  3. 选择组件

  • Additional Icons

  • On the Desktop // 添加桌面图标

  • Windows Explorer integration // 右键菜单添加以下两个选项

  • Git Bash Here

  • Git GUI Here

  • Git LFS (Large File Support // 大文件支持

  • Associate .git* configuration files with the default text editor // 关联.git后缀文件

  • Associate .sh files to be run with Bash // 关联.sh文件

  • Check daily for Git for Windows updates // 每天检查版本更新

  • (NEW!) Add a Git Bash Profile to Windows Terminal // 将Git Bash添加到Windows Terminal中

  • (NEW!)Scalar (Git add-on to manage large-scale repositories) Windows新开发的一种大规模仓库管理, 视情况而定

  1. 后续所有步骤无脑下一步

3、更新

1、在官网下载新版本,双击安装程序,窗口左下角勾选 Only show new options 选项,然后点击 Install

2、点击 Finish 完成更新

4、配置

1. 基础用户配置

bash 复制代码
# 设置用户名和邮箱(全局配置)
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

# 设置用户名和邮箱(仅当前仓库)
git config user.name "Your Name"
git config user.email "your.email@example.com"

# 查看配置
git config --list
git config user.name  # 查看特定配置

# 查看配置文件位置
git config --list --show-origin

2. 文件系统配置

区分大小写设置
bash 复制代码
# 查看当前仓库的大小写敏感设置
git config core.ignorecase

# 设置为大小写敏感(推荐)
git config core.ignorecase false

# 设置为大小写不敏感(Windows默认)
git config core.ignorecase true

# 全局设置
git config --global core.ignorecase false

说明

  • false: 大小写敏感,推荐设置
  • true: 大小写不敏感,Windows系统默认
  • 建议设置为 false,避免文件名大小写问题
行尾符配置
bash 复制代码
# 自动转换行尾符(推荐)
git config --global core.autocrlf true  # Windows
git config --global core.autocrlf input # macOS/Linux

# 不转换行尾符
git config --global core.autocrlf false

# 检查行尾符
git config core.autocrlf

3. Pull 策略配置

设置默认pull策略
bash 复制代码
# 设置为merge策略(默认)
git config --global pull.rebase false

# 设置为rebase策略
git config --global pull.rebase true

# 设置为fast-forward only
git config --global pull.ff only

# 查看当前设置
git config pull.rebase

三种策略对比

策略 命令 特点 适用场景
merge git pull 创建合并提交,保留分支历史 团队协作,需要保留完整历史
rebase git pull --rebase 线性历史,更清晰 个人开发,追求简洁历史
fast-forward only git pull --ff-only 只允许快进合并 严格的分支管理
推荐配置
bash 复制代码
# 个人开发推荐
git config --global pull.rebase true

# 团队协作推荐
git config --global pull.rebase false

4. 安全配置

bash 复制代码
# 设置凭证存储
git config --global credential.helper store  # 永久存储
git config --global credential.helper cache  # 临时存储(15分钟)

# 设置SSH密钥(推荐)
# 生成SSH密钥
ssh-keygen -t rsa -b 4096 -C "your.email@example.com"

# 添加到SSH代理
ssh-add ~/.ssh/id_rsa

5. 完整配置示例

bash 复制代码
# 基础配置
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --global core.editor "code --wait"

# 文件系统配置
git config --global core.ignorecase false
git config --global core.autocrlf input  # macOS/Linux

# Pull策略配置
git config --global pull.rebase true

# 别名配置
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'

# 安全配置
git config --global credential.helper store

5、提交规范

1、项目安装git工具

  • husky
  • commitizen

2、规范格式

optional scope\]: \[optional body

optional footer(s)

  • 类型(Type) :表示提交的类型,如feat(新功能)、fix(修复)、docs(文档更新)等。
  • 范围(Scope,可选) :指定提交影响的代码模块或功能区域。
  • 描述(Description) :简短描述提交的内容。
  • 正文(Body,可选) :提供更详细的描述,如变更的原因、影响范围等。
  • 脚注(Footer,可选) :提供额外信息,如关联的issue编号、破壊性变更的标记等。

例如:

git commit -m feat(login): Add login authorization feature

git commit -m docs:文档更新

3、具体属性

属性 描述
feat 新功能
fix 修改bug
docs 文档修改
style 格式修改
refactor 重构
perf 性能提升
test 测试
build 构建系统
ci 对CI配置文件修改
chore 修改构建流程、或者增加依赖库、工具
revert 回滚版本
相关推荐
Rhys..8 小时前
Git & GitHub 个人账户创建教程
git·github
wuyunhang12345610 小时前
Git----常用指令入门
git
越千年13 小时前
Git的“后悔药”全指南:reset、revert、restore 如何优雅地拯救手残
git
NiKo_W1 天前
Git 多人协作(1)
git
Rhys..1 天前
Git常用命令合集
大数据·git·elasticsearch
長琹1 天前
Git版本管理工具入门及常用命令讲解---小白版
git
AL流云。1 天前
一篇了解 Git 使用方法
git
清粥油条可乐炸鸡5 天前
gitflow在公司的全流程
git
少女续续念6 天前
国产 DevOps 崛起!Gitee 领衔构建合规、高效的企业协作工具链
git·开源