135

From time to time I find myself commit-amending using the same message.

Typically, I do:

  1. Add my changes to staging area.
  2. Do git commit --amend.
  3. Wait for the text editor to open.
  4. Save and close it (without changing the message).

There is anyway to tell git that I don't want to change the commit message (skipping the step of opening my text editor and saving the message)? Like:

  1. Add my changes to staging area.
  2. Tell git to amend my staging area to the last commit without asking me for another message.

I know I can avoid git firing up my text editor by doing git commit --amend -m "<message>". But this way I would have to retype the message.

Martin G
  • 17,357
  • 9
  • 82
  • 98
talles
  • 14,356
  • 8
  • 45
  • 58

2 Answers2

260

Try git commit --amend --no-edit.

Rob Bajorek
  • 6,382
  • 7
  • 44
  • 51
  • 1
    Note: The --no-edit flag was added in Git 1.7.9: https://github.com/git/git/blob/8858448bb49332d353febc078ce4a3abcc962efe/Documentation/RelNotes/1.7.9.txt#L45-L47 The other answer will work for previous Git versions – Pat Myron Nov 12 '18 at 18:11
19

This will amend the latest commit, using that same message, in one command:

git commit --amend -C HEAD
gylaz
  • 13,221
  • 8
  • 52
  • 58
  • This option works perfectly on centOS 6.7 (final). because --no-edit option is not yet avaiable in that platform, through a standard git yum install. NOTE: git version 1.7.1 – crsuarezf Oct 08 '15 at 15:13
  • 2
    From http://stackoverflow.com/a/10365442/710377: This option was added in Git 1.7.9. – meustrus Nov 30 '16 at 15:55