运用场景
对于最后一次提交,如果想修改提交信息,或者追加修改的文件,可以通过该指令去完成。
git commit --amend
修改提交信息
$ git checkout main
$ git commit --amend
第二次修改iss53
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Wed Feb 21 16:09:29 2024 +0800
#
# On branch main
# Your branch is up to date with 'origin/main'.
#
# Changes to be committed:
# modified: README.md
#
~
~
~
~
~
~
~
~
"~/git-practise/.git/COMMIT_EDITMSG" 13L, 325B
执行该指令,会启动文本编辑器,里面包含了最后一条提交信息,可以输入新的内容替换这条提交信息。
信息内容修改之后,按键盘 Esc
,再按 Shift + ;
,输入 wq
保存退出。
最后,通过 git push
添加 -f
、 --force
或者 --force-with-lease
选项,来强制推送本地提交历史覆盖服务器上的提交历史。
追加修改的文件
在最后一次提交完成后,因为忘记修改部分文件,所以想更改提交的快照,也可以通过该指令来完成。
$ git add .
$ git commit --amend
第二次修改iss53
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Wed Feb 21 16:09:29 2024 +0800
#
# On branch main
# Your branch is up to date with 'origin/main'.
#
# Changes to be committed:
# modified: README.md
#
# Changes not staged for commit:
# modified: README.md
#
~
~
~
~
~
"~/git-practise/.git/COMMIT_EDITMSG" 16L, 384B
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦