I branched my github project to create the static page the other day but messed up with my author name
https://github.com/ronaldsuwandi/le-simplepage/commits/gh-pages
How do I rename the author for the first commit for the branch?
I've tried
But no luck - I'm still really new to git..
EDIT: The answer given by Amber does not work if I want to change the first commit (e.g. if my commit history is A-B-C-D
and I would like to change the commit history of B
I can do git rebase -i A
. But I'm not sure what to do if I want to change commit history of A
itself.
git checkout gh-pages
git reset --hard 02bd
git commit --amend --author 'Ronald Suwandi <[email protected]>'
git cherry-pick 02bd..origin/gh-pages
git push -f
Just as in real life, changing history is not a trivial thing. ;)
In git a commit includes (among others) both the author name and the parent commit. Therefore you cannot simply change attributes like the author of a commit. The only thing you can do is throw away the old commit and create a new fixed one. But as the next commit did contain the original commit as a parent you have to change that commit, too. - But again you cannot do this but you need to replace the old one, etc.
There is git rebase
to help you with this kind of ugly things: It takes a series of commits and creates a completely new one with the changed history. As a branch in git is simply a pointer to a single commit, the rebase then just changes that pointer from the old history to the new one.
X-A-B-C-D <- "old master"
`a-b-c-d <- "new master"
As long as you are working on your local repository it is no problem to change history as much as you like. Things change as soon as you publish your commits by pushing them to a shared repository like github. If you already published the old history and now publish the new history, both versions are published and if others work on that repository, too, chances are good that the old version will find its way back to your history.
So generally just do not change history once you have published it. But if you are sure no one else is working on your remote repository you can do it anyways: Fix your history locally and force push it to the repository.
Changing history locally is easy with git rebase -i
. Unfortunately it is a bit more tricky for the root commit of your repository. See Change first commit of project with Git? for details.
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