Skip to content

Git

账户设置

全局账户设置:
git config --global user.name "张三"
git config --global user.email "张三@company.com"

局部账户设置:
git config user.name "李四"
git config user.email "李四@qq.com"
全局账户设置:
git config --global user.name "张三"
git config --global user.email "张三@company.com"

局部账户设置:
git config user.name "李四"
git config user.email "李四@qq.com"

Git 提交规范

commit: {
		feat: 'feat:新功能',
		fix: 'fix:修复',
		docs: 'docs:文档变更',
		style: 'style:代码格式(不影响代码运行的变动)',
		refactor: 'refactor:重构(既不是增加feature,也不是修复bug)',
		perf: 'perf:性能优化',
		test: 'test:增加测试',
		chore: 'chore:构建过程或辅助工具的变动,依赖更新/脚手架配置修改等',
		revert: 'revert:回退',
		build: 'build:打包',
		workflow: 'workflow :工作流改进',
		ci: 'ci:持续集成',
		types: 'types:类型变更',
}
commit: {
		feat: 'feat:新功能',
		fix: 'fix:修复',
		docs: 'docs:文档变更',
		style: 'style:代码格式(不影响代码运行的变动)',
		refactor: 'refactor:重构(既不是增加feature,也不是修复bug)',
		perf: 'perf:性能优化',
		test: 'test:增加测试',
		chore: 'chore:构建过程或辅助工具的变动,依赖更新/脚手架配置修改等',
		revert: 'revert:回退',
		build: 'build:打包',
		workflow: 'workflow :工作流改进',
		ci: 'ci:持续集成',
		types: 'types:类型变更',
}

git 使用教程

克隆仓库git clone https://***.git

查看文件状态git status

暂存文件git add .

提交暂存的文件,添加描述git commit -m ""

推送代码到远程仓库git push

拉取远程仓库的代码git pull

当前工作区保存到栈git stash

将git stash保存的更改恢复到工作区git stash pop

新建并切换到该分支git checkout -b develop

新建分支git branch develop

切换分支git checkout develop

分支合并:切换到主分支,合并develop

切换到主分支git checkout master

合并git merge develop

查看分支git branch

切换分支git checkout develop

推送代码到远程仓库git push origin develop

同步远程仓库git fetch origin

查看远程分支git branch -r

拉取远程分支git branch pc origin/pc

获取远程仓库状态,并删除本地没有对应远程分支的远程跟踪分支git fetch -p

删除本地分支git branch -d <branch_name>

Windows Git 路径问题解决方案

Windows 下使用 Git 常遇到以下痛点:

  • 无效路径错误
  • 克隆成功但检出失败
  • 路径过长导致操作失败
  • 文件名大小写混淆

一键配置(推荐)

bash
# 1. 关闭 NTFS 路径保护(解决无效路径/检出失败)
git config --global core.protectNTFS false

# 2. 开启长路径支持(避免 MAX_PATH 限制)
git config --global core.longpaths true

# 3. 严格区分文件名大小写(避免大小写混淆)
git config --global core.ignorecase false
# 1. 关闭 NTFS 路径保护(解决无效路径/检出失败)
git config --global core.protectNTFS false

# 2. 开启长路径支持(避免 MAX_PATH 限制)
git config --global core.longpaths true

# 3. 严格区分文件名大小写(避免大小写混淆)
git config --global core.ignorecase false

配置验证

bash
# 查看当前配置值
git config --global --get core.protectNTFS   # 应为 false
git config --global --get core.longpaths     # 应为 true
git config --global --get core.ignorecase    # 应为 false
# 查看当前配置值
git config --global --get core.protectNTFS   # 应为 false
git config --global --get core.longpaths     # 应为 true
git config --global --get core.ignorecase    # 应为 false

完整配置查看

bash
# 查看所有全局配置
git config --global --list | grep core
# 查看所有全局配置
git config --global --list | grep core