Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Git 中管理历史记录
  7. 修改提交
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

修改提交

请转至您刚才下载的git-tutorial/tutorial1目录。

当您检查此存储库的历史记录时,它将如下所示:

The history of repository

若要确认存储库的历史记录,请使用 git log 命令,您将看到以下内容:

$ git log
commit f01c8c09f09e14063feb13b24be592e507ea365b (HEAD -> main)
Author: yourname <yourname@yourmail.com>
Date:   Mon Jul 16 23:17:56 2012 +0900
    EDITED: append description of the add command
commit 0de54de5d846d5fb800cf0f4d74f0c79d2e0a186
Author: yourname <yourname@yourmail.com>
Date:   Mon Jul 16 23:16:14 2012 +0900
    first commit

让我们重写历史日志中的第一个提交。

首先,打开sample.txt文件,并添加下面的粗体文本。

Anyone can learn Git with this tutorial and Backlog add: Register a change in an index commit: Save the status of an index

使用--amend选项提交。

$ git add sample.txt
$ git commit --amend

您默认的编辑器将打开,其中包含您可以编辑的最新提交消息。对于本教程,让我们将消息更改为“Add direction of the Add and the Commit”,然后保存并退出文本编辑器。

提交消息现已更新。再次使用 log 命令来验证存储库历史和新的提交消息是否如下所示:

the result of "commit --amend"
$ git log
commit e9d75a02e62814541ee0410d9c1d1bf47ab1c057
Author: yourname
Date:   Mon Jul 16 23:17:56 2022 +0900

    Add direction of the Add and the Commit

commit 48eec1ddf73a7fb508ef664efd6b3d873631742f
Author: yourname
  Date:   Mon Jul 16 23:16:14 2022 +0900

      first commit

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life