Change information of commit on github

mucrolores
3 min readJul 11, 2021

--

There’re quite a few information in the commits likes message, author, date.
I’ll introduce methods to change the commit message and author in this page.

git log result

Suppose you’re github commits is like the picture below.

github commits

There’re two mainly situation you’ll need to change commit information.

  1. Change information of Latest pushed commit.
  2. Change information of Older pushed commit.

I’ll mainly using the command git rebase and git commit --amend in the content below.

Change information of Latest pushed commit

To Change the latest pushed commit, you could follow the command.

  • git commit --amend
  • Then you’ll see a vim editor like this.
  • edit the message and save quit.
  • If you just need to change the Author information of the commits use command git commit --amend --author="author_name <author@email.com>"
  • using git log to check if commit message had been change correctly
git log after git — amend
  • git push -f to push edited commit message to the repository.
    Becareful!! git push -f is a force push command will overwritten the repository on github, make sure what you’re doing before this.

Change information of Older pushed commit

The biggest different between change latest and older commit is you’ll have to call git rebase to edit older commits.

  • Call command git rebase -i HEAD~N N is for the number of commits you want to edit from HEAD, and you will see the page like below.
    Note: If you want to rebase to root commit, simply call git rebase -i --root instead.
git rebase
  • Edit the “pick” to “edit” of commit you want to edit information, then save quit.

From now on, you’re just like editing the latest commit information.

  • git commit --amend to edit the message
    git commit --amend --author="author_name <author@email.com>" to edit the author
  • Call git rebase --continue to finalize you rebase.
  • git push -f to push edited commit message to the repository.
    Becareful!! git push -f is a force push command will overwritten the repository on github, make sure what you’re doing before this.

Some of github issue

There’s an annoying issue if you’re editing the older commit after you git push -f
All the commits after edited commit will be regard as commit in same time on github

  • Using command git rebase --committer-date-is-author-date HEAD~N N is for the number of commits you want to update from HEAD.
  • push after rebase git push -f then you’ll see the correct commit time on github.

It’s better not using git push -f and git rebase -i if you know what you’re doing, enjoy:)

--

--

No responses yet