1

I have a bunch of git commits that need to be modified. I haven't pushed any of them yet, I've simply been doing:

git add .
git commit -m "message 1"
git add .
git commit -m "message 2"
git add .
git commit -m "message 3"
git add .
git commit -m "message 4"

Now I'm trying to add a line to all of these commits..

I thought you would do it this way:

1) Get the commit numbers:

$] git log
commit 931824f116637cf0f4d7dea98828f9cdfc6b9157
Author: ...
Date:   Tue Feb 4 17:30:19 2014 -0800

    message 1

commit 726adac71a0d8fdac4f62663e6081f1e784e4805
Author: ...
Date:   Tue Feb 4 16:25:17 2014 -0800

    message 2

commit d8aab763f2d2603fb1935648f1ffe80e26039209
Author: ...
Date:   Tue Feb 4 10:53:19 2014 -0800

    message 3

commit 931824f116637cf0f4d7dea98828f9cdfc6b9157
Author: ...
Date:   Tue Feb 4 17:30:19 2014 -0800

    message 4

2) Do "git commit --amend -c [commit number]"

git commit --amend -c 931824f116637cf0f4d7dea98828f9cdfc6b9157
git commit --amend -c 726adac71a0d8fdac4f62663e6081f1e784e4805
git commit --amend -c d8aab763f2d2603fb1935648f1ffe80e26039209
git commit --amend -c 931824f116637cf0f4d7dea98828f9cdfc6b9157

3) When the editor comes up, I type "i" to insert, then add some text to the message, then type ":wq" to save and quit...

But then the editor doesn't save the changes I've made to the commit messages... I do "git log" and the message still looks the same! It still says "message 1" eventhough I changed it to be "message 1 more text"...

When I re-run "git commit --amend..." for the same command, it still says "message 1", also... so it seems that it has had absolutely no effect..

Anything I'm doing wrong? I have correct "rights" to write to the files :(

1
  • 1
    I think you want git rebase -i HEAD~5... Commented Feb 5, 2014 at 19:38

1 Answer 1

4

You can't change existing commits. That's impossible.

What git commit --amend actually does, is that it creates a new commit that is a copy of your latest commit, also known as HEAD, with the changes that you specify.

This new commit then replaces your current HEAD.

The -c parameter specifies another commit to copy the message from, and edit in an editor. It does not affect that other commit in any way.

To do what you actually want to do, see http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

Sign up to request clarification or add additional context in comments.

2 Comments

Oh! Dang that's a bummer. Thank you for clearing this up! ^_^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.