Git 简明教程

Git - Commit Changes

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

Jerry has already committed the changes and he wants to correct his last commit. In this case, git amend operation will help. The amend operation changes the last commit including your commit message; it creates a new commit ID.

在 amend 操作之前,他检查提交日志。

Before amend operation, he checks the commit log.

[jerry@CentOS project]$ git log

上述命令将产生以下结果。

The above command will produce the following result.

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 commits the new changes with — amend operation and views the commit log.

[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 的新提交信息 −

Now, git log will show new commit message with new commit ID −

[jerry@CentOS project]$ git log

上述命令将产生以下结果。

The above command will produce the following result.

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