0

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.

Daniel Santos
  • 14,328
  • 21
  • 91
  • 174
  • http://stackoverflow.com/a/179147 – mm759 Sep 19 '16 at 12:40
  • 3
    Possible duplicate of [How to modify existing, unpushed commits?](http://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commits) – Vampire Sep 19 '16 at 12:41
  • I tried this, but it don't work with a old commit. Or maybe I just don't understand how to apply it to a old one.@mm759 – Daniel Santos Sep 19 '16 at 12:42
  • it's not "unpushed commits" is "Pushed commit" @Vampire – Daniel Santos Sep 19 '16 at 12:42
  • The answer still shows how to do it for pushed commits ;-) – Vampire Sep 19 '16 at 12:48
  • 2
    Btw. just in case you listen to the answer below. Be aware that all others that have this history already will hate you. Because each and every single branch created of any commit on top of that rewritten commit will have to be rebased manually to get things right. Read the bottom of the man-page of git-rebase about how to recover from upstream rebase what will be what you do. – Vampire Sep 19 '16 at 12:49

2 Answers2

3

Is that possible?

Yes, itzmeontv's answer covers this

how can I do it?

Don't. The commit message is part of the commit, and influences the SHA1 hash (along with the other metadata, like parent commit).

Changing the message therefore creates a new commit (with the same effect on the tree), and thus also rewrites every subsequent commit just to change their parent.

That is, it constructs a parallel duplicate timeline starting with a new version of that original commit. Anyone else working against the original timeline will be unhappy.

Useless
  • 64,155
  • 6
  • 88
  • 132
  • 1
    Note that even once you've persuaded everyone to tolerate your history rewrite, they'll still _have_ the old commit until it gets garbage collected, and can just tag it if they want it to live forever. – Useless Sep 21 '16 at 09:29
2

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/

itzMEonTV
  • 19,851
  • 4
  • 39
  • 49