0

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?

Community
  • 1
  • 1
George
  • 5,648
  • 5
  • 43
  • 63

2 Answers2

1

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:

  1. Check 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).
  2. Check if git doesn't use any credential helpers to avoid repetition. (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.

Community
  • 1
  • 1
Konrad 'Zegis'
  • 9,803
  • 1
  • 12
  • 18
0

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:

  1. Git bash into local git repository and print out a list of committers

    git shortlog -sne

  2. Decide on which set of commit names to merge. At the root of the repository:

    touch .mailmap

    vi .mailmap

  3. Input in this format:

    Proper name 1 <name1@example.com> unknown1 <badname1@example.com> Proper name 1 <name1@example.com> unknown2 <badname2@example.com> Proper name 2 <name2@example.com> unknown3 <badname3@example.com>

  4. Do a verification, and the names should now be merged:

    git shortlog -sne

George
  • 5,648
  • 5
  • 43
  • 63