<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Version Control on Qingchen Yu</title><link>https://zhgyqc.site/tags/version-control/</link><description>Recent content in Version Control on Qingchen Yu</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 01 Nov 2026 21:35:04 +0800</lastBuildDate><atom:link href="https://zhgyqc.site/tags/version-control/index.xml" rel="self" type="application/rss+xml"/><item><title>修改 Git Commit 消息指南</title><link>https://zhgyqc.site/blogs/2024-10-22-modify-git-commit-messages/</link><pubDate>Tue, 22 Oct 2024 00:00:00 +0000</pubDate><guid>https://zhgyqc.site/blogs/2024-10-22-modify-git-commit-messages/</guid><description>本文由 ChatGPT 辅助生成
有时候，我们会在提交代码时拼写错误 commit 消息，或者消息描述不够准确。幸运的是，Git 提供了方法来修改已经提交的历史记录，包括 commit 消息。本文将详细介绍如何修改任意数量的 commit 消息，并将它们推送到远程仓库。
修改历史 Commit 消息 如果你想修改之前的 commit 消息，你可以按照以下步骤进行：
运行以下命令来开始交互式修改：git rebase -i HEAD~n。这里的 n 表示你想要修改的最近提交次数。例如，如果你想修改过去五次的提交，可以使用 git rebase -i HEAD~5。这会启动一个交互式编辑器，显示最近几次提交的列表： pick &amp;lt;commit-hash-1&amp;gt; commit message 1 pick &amp;lt;commit-hash-2&amp;gt; commit message 2 pick &amp;lt;commit-hash-3&amp;gt; commit message 3 将你想要修改的 commit 前的 pick 改为 reword，像这样： reword &amp;lt;commit-hash-1&amp;gt; commit message 1 reword &amp;lt;commit-hash-2&amp;gt; commit message 2 reword &amp;lt;commit-hash-3&amp;gt; commit message 3 保存并退出编辑器。之后，Git 会依次打开每个需要修改的 commit 消息的编辑器，你可以在其中修改消息。修改完成后，保存并退出。 完成所有修改后，你会看到如下提示： Successfully rebased and updated refs/heads/main.</description></item></channel></rss>