讲师中心 微信公众号
AI工具推荐 视频效率加速

Git 教程

浏览13942
更新时间2025-08-21

Jerry 已经提交了更改,他想更正他的最后一次提交。 在这种情况下,git amend 操作会有所帮助。 修改操作会更改最后一次提交,包括您的提交消息; 它会创建一个新的提交 ID。

在修改操作之前,他会检查提交日志。

[jerry@CentOS project]$ git log

上面的命令会产生如下结果。

commit cbe1249b140dad24b2c35b15cc7e26a6f02d2277
Author: Jerry Mouse <jerry@tutorialspoint.com>
Date: Wed Sep 11 08:05:26 2013 +0530

Implemented my_strlen function

commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat <tom@tutorialspoint.com>
Date: Wed Sep 11 07:32:56 2013 +0530

Initial commit

Jerry 使用 --amend 操作提交新的更改并查看提交日志。

[jerry@CentOS project]$ git status -s
M string.c
?? string

[jerry@CentOS project]$ git add string.c

[jerry@CentOS project]$ git status -s
M string.c
?? string

[jerry@CentOS project]$ git commit --amend -m 'Changed return type of my_strlen to size_t'
[master d1e19d3] Changed return type of my_strlen to size_t
1 files changed, 24 insertions(+), 0 deletions(-)
create mode 100644 string.c

现在,git log 将显示带有新提交 ID 的新提交消息 −

[jerry@CentOS project]$ git log

上面的命令会产生如下结果。

commit d1e19d316224cddc437e3ed34ec3c931ad803958
Author: Jerry Mouse <jerry@tutorialspoint.com>
Date: Wed Sep 11 08:05:26 2013 +0530

Changed return type of my_strlen to size_t

commit 19ae20683fc460db7d127cf201a1429523b0e319
Author: Tom Cat <tom@tutorialspoint.com>
Date: Wed Sep 11 07:32:56 2013 +0530

Initial commit

精品课程

更多
前端入门_HTML5
前端入门_HTML5

共29课时 | 64.9万人学习

CSS视频教程-玉女心经版
CSS视频教程-玉女心经版

共25课时 | 41.2万人学习

JavaScript极速入门_玉女心经系列
JavaScript极速入门_玉女心经系列

共43课时 | 76.6万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn