Having issues with your git history? Perhaps you're not finding that you're credited with commits you believe that you should. This can be caused by a number of issues --perhaps your email is wrong on github, or incorrectly set in your local .git file. There are actually loads of reasons why this might be messed up, and while you should fix that --this guide is only going to teach you how to rewrite this evil, not how to prevent it.
The first thing we should do is learn a couple of helpful commands that will show us what needs to be fix and indicate our progress.
These must be performed inside of the repository about which you wish to glean information.
git shortlog -sn
This command will show the number of commits and author name sorted from most to least commits as shown below:git log --pretty="%an %ae%n%cn %ce | sort | uniq
This command will show all of the known name and email tuples from commits and sort them alphabetically. This way, you can see which emails need to be replaced. An example is below:OLD_EMAIL
, CORRECT_NAME
, and CORRECT_EMAIL
are equal to so that the script will accomplish the change you desire. Refer to the earlier helpful commands if you are unaware of the old email.sh name.sh
where name is the name of the scriptgit push --force --tags origin 'refs/heads/*'
(By the way, these changes won't apply to protected branches)git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch Rakefile' HEAD
When you're done, you should see a change in the output of the helpful commands. For example, the first of the helpful commands will show a change in the number of commits attributed to the user you are not applying them to. See the image below and compare it to the one above, paying special attention to the user Zachary Danz: