Daniel Santos Daniel Santos - 2 months ago 11
Git Question

How to modify a old existing pushed commits?

Looking at my commit tree I saw a relative old pushed commit with incorrect description.
I would like to change it. Is that possible? how can I do it?

The commit was already pushed to server. The commit is an old commit with a lot of commits pushed after it. I would like to just change the message, not the content.

Answer

You have to do force push(not recommended) anyway which rewrites entire tree from that commit.

git rebase -i HEAD~n # Displays a list of the last n commits on the current branch

From the list something like,

pick e499d89 Delete CNAME
pick 0c39034 Better README
pick f7fde4a Change the commit message but push the same commit.

# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd

Change pick to reword like

pick e499d89 Delete CNAME
reword 0c39034 Better README #line to change the message
pick f7fde4a Change the commit message but push the same commit.

# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
  • Save and close the commit list file. In each resulting commit file, type the new commit message, save the file, and close it.

    Then

    git push --force
    

Hope this helps.for more info https://help.github.com/articles/changing-a-commit-message/