Git 推荐配置
#工程化
推荐配置
全局配置:
- 默认的主分支名称为main, 统一
git config --global init.defaultBranch main- 提交时转换为 LF,检出时不转换
git config --global core.autocrlf input- 避免不必要的合并提交
当你执行
git pull时,Git 默认会执行fetch和merge操作,这可能会导致本地分支的合并冲突或其他变化
git config pull.rebase trueGit 的 core.autocrlf 配置
true: 提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf trueinput: 提交时转换为 LF,检出时不转换
git config --global core.autocrlf inputfalse: 提交检出均不转换
git config --global core.autocrlf false验证设置
git config pull.rebase最佳实践
不要直接把代码推送到主分支, 先创建一个新的分支, 在经过review之后, 确认无误之后在合并代码到主分支
git checkout -b beta
git add .git commit -m "feat: "git push main betagit commit 模板
提交时显示 commit 模板
- 创建
.gitmessage文件, 填写内容
# head: <type>(<scope>): <subject># - type: feat, fix, docs, style, refactor, test, chore# - scope: can be empty (eg. if the change is a global or difficult to assign to a single component)# - subject: start with verb (such as 'change'), 50-character line## body: 72-character wrapped. This should answer: # * Why was this change necessary? # * How does it address the problem?# * Are there any side effects?## footer:# - Include a link to the ticket, if any.# - BREAKING CHANGE#- 创建
.gitconfig文件, 填写映射
[commit] template = ./.gitmessage参考