Reputation: 6084
I have Git installed on a windows box, and several git users set up who authenticates using password. However, all git commands (for instance, git pull) performed on the local windows machine (via git bash) requires no authentication. Commits from that shell shows up author as "unknown". While I'm aware that a user name and email can be set to prevent commits from "unknown", I want to enforce authentication so a user will have to login before any git actions.
Second, how can I combine the "unknown" author with an existing user such that the commit history is merged?
Upvotes: 0
Views: 315
Reputation: 6084
As there might be more duplicated git users (in name or email variations) in future, I've decided to use a .mailmap file. Here's what I used to fix my problem:
Git bash into local git repository and print out a list of committers
git shortlog -sne
Decide on which set of commit names to merge. At the root of the repository:
touch .mailmap
vi .mailmap
Input in this format:
Proper name 1 <[email protected]> unknown1 <[email protected]>
Proper name 1 <[email protected]> unknown2 <[email protected]>
Proper name 2 <[email protected]> unknown3 <[email protected]>
Do a verification, and the names should now be merged:
git shortlog -sne
Upvotes: 0
Reputation: 16511
About 2nd part of your question: there's git filter-branch
command that lets you rewrite Git history. Usage:
git filter-branch --env-filter '
oldname="(old name)"
oldemail="(old email)"
newname="(new name)"
newemail="(new email)"
[ "$GIT_AUTHOR_EMAIL" = "$oldemail" ] && GIT_AUTHOR_EMAIL="$newemail"
[ "$GIT_COMMITTER_EMAIL" = "$oldemail" ] && GIT_COMMITTER_EMAIL="$newemail"
[ "$GIT_AUTHOR_NAME" = "$oldname" ] && GIT_AUTHOR_NAME="$newname"
[ "$GIT_COMMITTER_NAME" = "$oldname" ] && GIT_COMMITTER_NAME="$newname"
' HEAD
For more information please check git docs, or this dedicated article on github.
Although it can be real pain if you have many existing users identified as "unknown".
And about first part I would:
user.name
and user.email
in git config. These have nothing
to do with credentials, but git uses them to store authorship
information. It's possible that you need to set them up (as global
with git config --global
to use for every repository, or as
repository-based with git config
).git config -l
), if it does - remove it (I believe git config --global --unset credential.helper
but I'm sure).You may want to check this or this answers.
Upvotes: 1