问题
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.
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.
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.
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?
Note: All of the previously mentioned operations were done via macOS and the built-in terminal.
回答1:
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.
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.
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.
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
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
.
来源:https://stackoverflow.com/questions/60138385/difference-between-local-git-config-parameters-and-github-account