Oleg2718281828
Oleg2718281828

Reputation: 1039

changing the last commit message without committing newest changes

My ideal workflow would consist of the following steps

  1. edit the code
  2. compile
  3. git commit -a -m "commit message"
  4. start running the new binaries, tests, etc. (may take 10+ minutes)
  5. start new changes, while the binaries are still running
  6. when step # 4 is finished, edit the commit message from step # 3, without committing the changes introduced in step # 5, by adding, say, "test FOO failed"

I cannot use git commit -a --amend -m "new commit message", because this commits the new changes as well. I'm not sure that I want to bother with staging or branching. I wish I could just edit the commit message without committing any new changes. Is it possible?

Upvotes: 7

Views: 3477

Answers (3)

Gregor Müllegger
Gregor Müllegger

Reputation: 5123

You can also use:

git rebase -i HEAD^

This will open up your text editor and let's you change the last commit. You need to replace the word pick in the beginning of the line with reword, save the file and exit. After that a new text editor will open up that let's you change the commit message.

That sounds a bit more work than the suggested git commit --amend approach, but works also for older commites. So if you found that you want to change two messages in the last ten commits, you can run git rebase -i HEAD~10 and change the word pick again into reword and change both of those messages.

Just for the curious: -i stands for interactive rebasing.

Upvotes: 2

Matt Enright
Matt Enright

Reputation: 7494

There's no need to stash or do anything else here.

git commit --amend -m 'Your new message.'

will not commit any new changes (note the lack of -a flag), provided that you haven't explicitly added them to the index (using git add, for example).

Upvotes: 16

Kjuly
Kjuly

Reputation: 35191

Just:

$ git stash
$ git commit --amend -m "Your Modified Message"
$ git stash apply

Upvotes: 4

Related Questions