本地Git配置参数和GitHub帐户之间的区别? [英] Difference between local Git config parameters and GitHub account?

查看:44
本文介绍了本地Git配置参数和GitHub帐户之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我最近开始使用GitHub进行大学作业,但是在此之前,我一直在使用私有GitHub帐户.但是,对于这些特定任务,我们要求将终端(git config --global user.name/user.email)中的local(?)git参数更改为我们的大学ID和电子邮件地址.

Background: I've recently started using GitHub for university assignments, but before that I've been using a private GitHub account. However, for these specific tasks we were asked to change the local(?) git parameters in terminal (git config --global user.name/user.email) to our college ID and e-mail address.

首次提交并推送代码后,GitHub中的commits选项卡显示我的大学ID为提交的用户,当我尝试将其悬停/单击时,什么也没发生.

After committing and pushing the code for the first time, the commits tab in GitHub showed my college ID as the user who committed and when I tried hovering over it/clicking it, nothing happened.

对于第二个任务,在另一个仓库中,我像以前一样更改了git参数,但是这次在GitHub上的提交显示在我的个人用户名下,我可以单击图片查看我的帐户.此外,git log in终端仍然显示提交用户名是我的大学ID,而不是我的GitHub帐户用户名.

For a second task, in a different repo, I changed the git parameters, as before, but this time the commits on GitHub were shown under my personal username and I could click on the picture to see my account. Furthermore, git log in terminal still showed that the commit username was my college ID, not my GitHub account username.

所以我的问题是:git config参数和GitHub帐户信息之间有什么区别?更改git config参数是否有任何重要性,并且该信息在任何地方都可见?

So my question is: What is the difference between git config parameters and GitHub account information? Is there any importance in changing the git config parameters and will that information be visible anywhere?

注意:前面提到的所有操作都是通过macOS和内置终端完成的.

Note: All of the previously mentioned operations were done via macOS and the built-in terminal.

推荐答案

GitHub根据其电子邮件地址将提交与帐户关联.如果我在一个帐户上有bk2204@example.com,在另一个帐户上有bmc@example.net,那么我在一次提交中使用哪个帐户来确定它与哪个帐户相关联.

GitHub associates a commit with an account based on its email address. If I have bk2204@example.com on one account and bmc@example.net on a different one, then which one I use in a commit determines with which account it's associated.

更改 user.email 配置设置可控制在提交中使用哪个电子邮件地址,这就是为什么您看到它与其他用户相关联的原因.

Changing the user.email config setting controls which email address is used in a commit, which is why you're seeing it being associated with a different user.

有两个不同的配置文件,它们在不同的作用域内运行.您使用了-global 选项,该选项为您的用户(即macOS用户)设置配置,因为它会将数据存储在您的主目录中.如果只想为给定的存储库更改它,则可以省略-global 选项,它将配置为仅在给定的存储库上运行.

There are a couple different config files that operate at different scopes. You used the --global option, which sets your configuration for your user (that is, your macOS user) because it stores data in your home directory. If you want to just change it for a given repo, then you can omit the --global option, and it will be configured to operate only on the given repo.

如果将所有大学工作存储在一个路径下,则可以将以下内容添加到〜/.gitconfig 中,然后运行 git config -f〜/.gitconfig.universityuser.email me@example.edu ,事情就可以了:

If you store all of your university work under one path, you can add something like the following to your ~/.gitconfig and run git config -f ~/.gitconfig.university user.email me@example.edu and things will work:

[includeIf "gitdir:~/checkouts/university"]
    path = ~/.gitconfig.university

请注意,这需要更新的Git;您可以通过运行 git config --help 并搜索 includeIf 来检查您的版本是否支持该版本.

Note that this requires a more recent Git; you can check if your version supports it by running git config --help and searching for includeIf.

这篇关于本地Git配置参数和GitHub帐户之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆