Tin Nguyen Tin Nguyen - 1 year ago 106
Git Question

Github invalid author email commits, no contribution activity

Recently, I did some commits without config user.email. Is there any way to edit those commits to be recognized as contribution on my GitHub profile. (there're no commit email - to add to as GitHub account - as you can see in the log bellow)

Here some recent commit from git log command:

(the last/first one with email is commited after I config user.email)

commit 4ae6cc5c00e380c70072f9647b29dc242d2682d1
Author: Tin Nguyen <my-Gmail@gmail.com>
Date: Thu Sep 22 11:00:30 2016 +0700

delete some unnecessary code

commit 275362c077bb0495318d37b965c90beba2cb79b3
Author: Tin Nguyen <Tin Nguyen>
Date: Wed Sep 21 07:41:51 2016 +0700

modify database rules

commit c6b3af19c24627cafd862eff7449bc5d3f95cfbc
Author: Tin Nguyen <Tin Nguyen>
Date: Sun Sep 18 14:14:23 2016 +0700

Answer Source

Well, if you didn't share your work with someone else (if they didn't pull/clone/fork it yet), you can edit those by doing an interactive rebase, for example:

git rebase -i c6b3af19^
# change the comits you want to edit to "e" or "edit", leave the other on "p", "pick"
git commit --amend --author "Tin Nguyen <my-Gmail@gmail.com>"  --no-edit
git rebase --continue
#repeat the two last steps until done

Or more complex, but faster (one-liner):

git filter-branch --env-filter 'GIT_AUTHOR_EMAIL="my-Gmail@gmail.com"' c6b3af19^..HEAD HEAD

Or without using filter-branch (note that you must have correctly set your name and mail globally):

 git rebase c6b3af19^ --exec 'git commit --amend --no-edit --reset-author'

Just be aware that both will overwrite authorship information from c6b3af19 to the last commit you did, they are incomplete in the case you have other authors who committed more recently.

Note that in every case, you will then have to do a forced push to your remote repository, with git push -f

In any case, I suggest you to create a new branch before attempting to do this kind of changes. You can also use the reflog to recover if something bad happens, or just git checkout 4ae6cc5c, which was your latest commit to date. But as a rule of thumb, I think it is better to branch before doing any history rewrite.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download