我在承诺信中写错了。

我怎么能改變訊息呢?承諾尚未推動。


当前回答

如果您正在使用 Git GUI,您可以更改未被推的最后一个承诺:

Commit/Amend Last Commit

其他回答

使用

git commit --amend

要详细理解,一个很好的帖子是 4. 重新写 Git 历史. 它也谈论什么时候不使用 git commit --amend。

啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊

另一种方法是删除最后的承诺,但保持它的变化,这样你就不会失去你的工作。

git reset --soft HEAD~1
git commit -m 'New and corrected commit message'

我总是这样做,如果我忘记添加文件或做出更改。

请记住指定 - 软而不是 - 硬,否则你会失去这个承诺完全。

更新您的最后一个错误的承诺消息与新的承诺消息在一个行:

git commit --amend -m "your new commit message"

或者,尝试 Git 重新设置如下:

# You can reset your head to n number of commit
# NOT a good idea for changing last commit message,
# but you can get an idea to split commit into multiple commits
git reset --soft HEAD^

# It will reset you last commit. Now, you
# can re-commit it with new commit message.

使用重新设置将命令分成较小的命令

git 重新设置可以帮助您将一个承诺分成多个承诺:

# Reset your head. I am resetting to last commits:
git reset --soft HEAD^
# (You can reset multiple commit by doing HEAD~2(no. of commits)

# Now, reset your head for splitting it to multiple commits
git reset HEAD

# Add and commit your files separately to make multiple commits: e.g
git add app/
git commit -m "add all files in app directory"

git add config/
git commit -m "add all files in config directory"

在这里,你成功地将最后的承诺分成两项承诺。

我意识到我已经推着一个承诺与一个类型在其中。为了放弃,我做了以下事情:

git commit --amend -m "T-1000, advanced prototype"
git push --force

警告:强迫推你的变化将重新写下远方分支与你的当地一个. 确保你不会过度写下任何你想保持的东西. 也要小心强迫推一个修改(重新写)承诺,如果其他人与你分享分支,因为他们将需要重新写下自己的历史,如果他们有旧的副本的承诺,你刚刚重新写。

如果您正在使用 Git GUI 工具,则有一个按钮称为 修改最后的承诺. 点击该按钮,然后它将显示您的最后的承诺文件和消息. 只需编辑该消息,您可以承诺它一个新的承诺消息。

或使用此命令从控制台/终端:

git commit -a --amend -m "My new commit message"