我目前正在处理两个项目,当我推送到这些项目时,它们期望我将本地的用户名和电子邮件配置为不同的数据。因此,我一直在更新我的配置文件,例如:
git config --local user.email "namelastname@domain.example"
由于它们是不同的存储库,是否有办法为每个存储库定义一个本地电子邮件?
也许在 .gitconfig
文件中?
我目前正在处理两个项目,当我推送到这些项目时,它们期望我将本地的用户名和电子邮件配置为不同的数据。因此,我一直在更新我的配置文件,例如:
git config --local user.email "namelastname@domain.example"
由于它们是不同的存储库,是否有办法为每个存储库定义一个本地电子邮件?
也许在 .gitconfig
文件中?
只针对一个代码库,请进入相关的代码库目录并执行以下操作:
git config user.name "Your Name Here"
git config user.email your@email.example
对于(全球)默认电子邮件(这在您的~/.gitconfig文件中已配置):
git config --global user.name "Your Name Here"
git config --global user.email your@email.example
您可以使用以下命令检查Git设置:
git config user.name && git config user.email
如果您在特定的存储库中设置了新用户/配置(与全局不同),则应显示该本地配置,否则将显示您的全局配置。
git commit --amend --reset-author --no-edit
,这将重置当前提交以使用本地配置(在运行上述命令后)。 - Rio Weber您可以通过在终端上打印以下命令来确认:
git config --global user.name
git config user.name
或者只需编辑 .git\config
文件,并在某个地方添加这三行:
[user]
name = YourName
email = your@email.com
git config --local credential.helper ""
git push origin master
这会要求提供当前仓库的用户名和密码。
通常我倾向于在公司项目和个人项目(在GitHub上)中使用不同的diff名称/电子邮件
在需要指定用户/电子邮件的git仓库中运行以下命令:
git config user.name <user-name>
git config user.email <user-email>
credential.username
选项和本地配置项选项,它们将要求进行身份验证密码。即使在 Mac 上使用 Git 凭据管理器也可以使用此方法。有关更多信息,请参见:https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git。因此,您可以为两个不同的 GitHub 帐户缓存至少两个不同的密码。