Change comment from older commits using SHA ID

Suppose I have 3 commits:

Added bar.txt     (3)
Second Commit     (2)
Initial Commit    (1)

How can I change the commit message from (2)using my SHA ID? The end has not yet been ported to the remote repository.

I tried: git commit --amend -m "Added foo.txt" 8457931

8457931 - The first 7 numbers from the SHA identifier.

The reason why this is not a duplicate: I ask how to change the commit message using the SHA identifier to indicate the commit I would like to change, as opposed to the related question.

+4
source share
1 answer

Do an interactive reboot, it is described in https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History

git rebase -i HEAD~2

'pick' ( commit) 'reword' . , , , origin/HEAD points

: ( ~1 )

git rebase --interactive <your_sha>~1

:

pick b35b85c second commit
pick 9cc745b Initial commit

, , pick reword:

reword b35b85c second commit
pick 9cc745b Initial commit

. , . . .

+4

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


All Articles