1

I am wondering if I could change the description of the past git commits. Anyone knows? for example, for commit 1234556, the original description is "abc", I want to change it to "123"

Adam Lee
  • 24,710
  • 51
  • 156
  • 236
  • 3
    Possible duplicate of [Edit an incorrect commit message in Git](http://stackoverflow.com/questions/179123/edit-an-incorrect-commit-message-in-git) – px5x2 Nov 26 '15 at 08:57

1 Answers1

4

This involves rewriting history. You shouldn't do that if you already pushed the commits to a place accessibly by others. However, if you know that nobody else has fetched your changes yet, it's safe to do.

  • If it's the latest commit, run git commit --amend and edit the message.
  • If it's an older commit, run git rebase -i 1234556^ (don't forget the ^), then replace pick with reword in the line of the commit you want to change and exit the editor. This will open another editor where you can edit the commit message right afterwards.

In both cases, you need to git push -f (forced push) afterwards unless the commits hadn't been pushed yet.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636