4

I know you can do git --amend to change the commit message of the latest commit. But how do I change the second newest commit message? Here's what my commit looks like now:

commit eca1b2db14da8ace66aed172056c6e7aaf323093
Author: Adam Sandler
Date:   Fri Jul 13 18:00:13 2012 -0700

    Pre-final work on appending new items on top

commit 7d21bbfea24cb72eafbe0213cad6339354078a81
Author: Adam Sandler
Date:   Fri Jul 13 11:57:40 2012 -0700

    Pre-final work on appending new item on top.

    Loading more  when user reaches the end of the scroll view

I want to change the commit 7d21bbfea24cb72eafbe0213ca that has two messages in it.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
xonegirlz
  • 8,889
  • 19
  • 69
  • 127
  • possible duplicate of [How can I amend a previous git commit](http://stackoverflow.com/questions/5587880/how-can-i-amend-a-previous-git-commit) – Daenyth Jul 15 '12 at 01:47

1 Answers1

5

It seems there are always many ways to do things in git, and I'm not an expert, but here's what I do in that situation:

$ git rebase -i HEAD~2

That brings up an editor with something like:

pick eca1b2d Pre-final work on appending new items on top
pick 7d21bbf Pre-final work on appending new item on top.

with some instructions below that. If you change pick to reword on the commit whose message you'd like to change, then save and exit the editor, you'll have another editor opened where you can reword the commit message.

I only ever do this on commits I haven't pushed yet. If you've already pushed the commit whose message you're changing, you'll want to read this: How do I recover/resynchronise after someone pushes a rebase or a reset to a published branch?

Community
  • 1
  • 1
Darshan Rivka Whittle
  • 32,989
  • 7
  • 91
  • 109
  • I've actually merged it with another branch and doing so gives me the commit message from the other commit – xonegirlz Jul 16 '12 at 03:46