$ git commit --amend not altering / saving commit message

问题描述 投票:0回答:1

我最近$ git add .我对我的一个存储库进行了一些更改,然后是$ git commit -m'INcorrect commit message'

我决定使用以下命令将错误的提交消息更改为“更正提交消息”:

$ git commit --amend

我这样做的说明可以在这里找到:https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

我使用Atom,因此Atom打开时显示“INcorrect commit message”,我将其更改为“更正提交消息”并保存我的更改。

保存更改后的提交消息后,我做了一个$ git log -1,希望看到“正确的提交消息”;但是,我仍然看到'不正确的提交消息'。

我究竟做错了什么?

注意

就在此之前,我按照以下说明将我的git编辑器从Sublime更改为Atom:How do I make Git use the editor of my choice for commits?

我基本上用过:

$ git config --global core.editor "atom"

$ export GIT_EDITOR=atom

我现在意识到我不必两个都做,但我也意识到这可能也没有伤害。

git github atom-editor git-commit git-commands
1个回答
3
投票

有两件事为我解决了这个问题。

正如@torek在我的原始帖子附带的评论中指出的那样,在调用Atom时设置--wait参数会阻止git从$ git commit --amend命令返回。显然,这对于git成功捕获已更改的提交消息是必要的,而不是在消息被更改之前返回。说得通。

$ git config --global core.editor "atom --wait"

显然,如果我没有明确保存我更改的提交消息(mac上的命令+),它将永远不会被保存。我必须这样做才能获取提交消息以识别我更改的提交消息。

起初这看起来很明显;但是,如果我改变了我的提交信息并点击了关闭窗口按钮(Mac上窗口左上角的'x'),会发生奇怪的事情......

如果我改变了我的提交消息,使用关闭窗口按钮('x')关闭Atom,然后执行$ git log -1命令,提交消息将显示原始未更改的提交消息。没什么奇怪的。

但是,如果我然后执行另一个$ git commit --amend命令,Atom将打开并显示以前的$ git commit --amend命令中更改的提交消息!如果你问我,这是非常奇怪的行为。不是一个git guru,让我们说这并没有消除对我的任何困惑。

底线

附加--wait参数($ git config --global core.editor "atom --wait"),并在执行$ git commit --amend时在Atom(mac上的命令+ s)中显式保存更改的提交消息。

© www.soinside.com 2019 - 2024. All rights reserved.