Git 提交时会记录用户名和邮箱,这些信息会显示在版本历史中。邮箱是关联头像的关键。
# 设置全局用户名和邮箱
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"
如果使用远程代码托管平台(如 GitHub、GitLab),平台会根据你注册时绑定的邮箱显示头像:
Gravatar 是一个全球通用的头像服务,支持通过邮箱关联头像:
在本地终端或 IDE 中,Git 不会直接显示头像,但某些工具(如 GitKraken、SourceTree)可能会通过 API 从远程平台拉取头像。
# 查看当前Git配置
git config --list
# 检查用户名和邮箱
git config user.name
git config user.email