Git: change HEAD commit message without touching the index

I know I can use git commit --amend --file=path-to-my-new-message , but this will also change the incremental changes. Of course, I could hide and then apply & drop stash, but is there a faster solution to change the HEAD commit message without making phased changes (and user interaction)?

+6
source share
3 answers

According to the git commit --amend --only man page git commit --amend --only job should run without any given paths, however this does not work for me. In the process, you can temporarily add the file and delete it again by changing twice:

 touch tmp git add tmp git commit --amend -m "new message" tmp git rm tmp git commit --amend -m "new message" tmp 
+2
source

You can write a new commit message to a file (say msg.txt ) and use git commit-tree , for example.

 new_head=$(git commit-tree HEAD^{tree} -p HEAD^ <msg.txt) git reset --soft $new_head 

This assumes that the commit you are correcting has one parent, unless you need to supply -p HEAD^2 -p HEAD^3 ... .

It is a little ugly and low. It may be easier for you to hide your changes and use direct "change."

 git stash git commit --amend git stash pop --index 

As @Jefromi points out, you can also use a temporary index file for a change operation, for example.

 GIT_INDEX_FILE=.git/tmpidx git reset GIT_INDEX_FILE=.git/tmpidx git commit --amend rm .git/tmpidx 
+7
source

You can git rebase -i HEAD^ and then change pick to reword in the editor open git -rebase. After that, you will be offered a new commit message.

0
source

Source: https://habr.com/ru/post/904545/


All Articles