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