git commit - Git amend/reword (without adding/changing files) -


often want edit commit message without having re-select file-set last commit.

git commit file1.c file2.c 

accidental typo in commit message.

git commit file1.c file2.c --amend 

this works, id not have re-select file-set original commit, once accidentally did git commit -a --amend , added many changes unintentionally.

i know git rebase -i head~1 replace pick with r (re-word), ends being few steps.

is there way re-word last commit in 1 step without including new files?

amending message without staged changes

as long don't have changes staged in staging area, can use

git commit --amend 

to edit previous commit's message1.

amending message with staged changes

however, if do have changes staged, can use --only (or -o) flag in combination --amend edit message of previous commit, without committing staged changes:

git commit --amend --only git commit --amend -o # shorter 

this option pointed out david ongaro in answer.

documentation

as stated in git commit documentation (emphasis mine):

-o --only   

make commit paths specified on command line, disregarding contents have been staged far. default mode of operation of git commit if paths given on command line, in case option can omitted. if option specified --amend, no paths need specified, can used amend last commit without committing changes have been staged.

1as mentioned minitech , others.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -