Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the last commit message without committing newest changes

Tags:

git

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?

like image 316
Oleg2718281828 Avatar asked Jul 01 '12 23:07

Oleg2718281828


People also ask

How do I amend not the last commit?

use git commit --amend to make changes, or. use git reset @~ to discard the last commit, but not the changes to the files (i.e. take you to the point you were at when you'd edited the files, but hadn't committed yet).

How do I overwrite last commit message?

You can change the most recent commit message using the git commit --amend command. In Git, the text of the commit message is part of the commit. Changing the commit message will change the commit ID--i.e., the SHA1 checksum that names the commit. Effectively, you are creating a new commit that replaces the old one.


2 Answers

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).

like image 102
Matt Enright Avatar answered Oct 20 '22 21:10

Matt Enright


Just:

$ git stash
$ git commit --amend -m "Your Modified Message"
$ git stash apply
like image 22
Kjuly Avatar answered Oct 20 '22 21:10

Kjuly