git commit --amend without asking for message

GitGit CommitGit Amend

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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

git commit --amend -C HEAD

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontallesView Question on Stackoverflow
Solution 1 - GitRob BajorekView Answer on Stackoverflow
Solution 2 - GitgylazView Answer on Stackoverflow