修改Git Commit Message
最近遇到手误写错commit message的情况,这里记下如何修改commit message
git commit –amend
amend 是在上一次提交的基础上修改内容,包括 commit message
如果新增文件修改,需要先执行
| 1 | git add <file> | 
如果是想要修改上一次提交的commit message,我们只需要执行
| 1 | git commit --amend | 
在跳出的页面中修改即可。
不过修改后,需要使用force,才能提交至远端库。
| 1 | git push <remote> -f | 
git rebase -i
这里我建了一个demo, git logg 查看一下历史commit,如图
git logg=’logg = log –graph –decorate –oneline –abbrev-commit –all’ 可在.gitconfig文件中添加此alias

例:这里我想修改中间两个commti message
只需要找到对应commit 的前一个hash值3fdcc3e,执行
| 1 | git rebase -i 3fdcc3e | 

git rebase -i 的功能很强大, 这里讲下
reword,具体使用可以google
这里我们选择reword,就像注释所说use commit ,but edit the commit message,这是专门来修改commit message的,将需要更改的commit 前缀改为r 或 reword

:wq后,弹出修改页面,修改相应的commit message即可

再次查看git logg,可以发现commit message已经被修改了,不过还可以发现rebase过的commit hash也变了,rebase -i是重新生成了一个commit
