On the first project I've done using a github repo, my initial commits were all over the place, and not linked with my github account, instead the shown authors for said commits were names such as my pc User default name, from commiting and pushing directly from the IDE (Apache NetBeans). Now I'd like to change those so that my github account would have registered those commits as contributions.
Upon further research, I found some methods that seemed to do the job, but either those were not the solution to my problems, or I executed them wrongly somehow.
Here's an example of a unlinked commit, and here is what they should look like.
Here's the first method i've tried:
git filter-branch --commit-filter '
if [ "$GIT_AUTHOR_NAME" = "WrongName" ]; then
GIT_AUTHOR_NAME="YourName"
git commit-tree "$@"
else
git commit-tree "$@"
fi' HEAD
git push --force
After following these steps, I got this message:
Cannot create a new backup.
A previous backup already exists in refs/original/
Force overwriting the backup with -f
So here's what I did:
git show-ref refs/original/*
git update-ref -d refs/original/refs/heads/master
git push --force
It is worth noting that none of these worked, or at least, did not give any response to executing each code (no messages). Also found this person who had a similar experience as to the found "solutions" to their problem, although it is a different problem.
There's a built-in mechanism for switching commit authors git commit --amend --author 'Test-Auth <[email protected]>' -- this fixes latest commit.
ex:
$ git log
commit 5f5dccf73ecfe838ea2ed84a8fcc6b4379fc23dd (HEAD -> master)
Merge: 1320d0a 5baab1e
Author: Alex Dascal <-------@---------->
Date: Wed May 29 09:28:37 2024 +0300
Merge remote-tracking branch 'origin'
commit 1320d0a8dfd533397c5a06df6421d79d36d884e8
Author: Alex Dascal <-------@---------->
Date: Wed May 29 09:27:39 2024 +0300
Test commit
$ git commit --amend --author 'Test-Auth <[email protected]>'
[master fd1a225] Merge remote-tracking branch 'origin'
Author: Test-Auth <[email protected]>
Date: Wed May 29 09:28:37 2024 +0300
Committer: Alex Dascal <-------@---------->
$ git log
commit fd1a22503d08af6d230016e9b38872a246469c58 (HEAD -> master, origin/master, origin/HEAD)
Merge: 1320d0a 5baab1e
Author: Test-Auth <[email protected]>
Date: Wed May 29 09:28:37 2024 +0300
Merge remote-tracking branch 'origin'
If you want to change multiple commits at once this will become a bit tedious but you can git rebase -i --root and then in vim pick the commits you want to change or use :%s/^pick/edit/g to change all of them and edit the author by using the command show above. When you are done you can force push back into your repo.
!!Changing anything on a commit (even author) will reset it's hash - Just FYI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With