xonegirlz
xonegirlz

Reputation: 8977

How to amend the second newest commit

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.

Upvotes: 4

Views: 1697

Answers (1)

Darshan Rivka Whittle
Darshan Rivka Whittle

Reputation: 34071

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?

Upvotes: 5

Related Questions