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
冷冷的火花