简体   繁体   中英

“git commit --amend -c <commit>” not saving changes

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 :(

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM