简体   繁体   English

$ git commit --amend不更改/保存提交消息

[英]$ git commit --amend not altering/saving commit message

I recently $ git add . 我最近$ git add . some changes I made to one of my repositories followed by $ git commit -m'INcorrect commit message' . 我对其中一个存储库进行了一些更改,然后是$ git commit -m'INcorrect commit message'

I decided to change the incorrect commit message to 'Correct commit message' using: 我决定使用以下方式将错误的提交消息更改为“正确的提交消息”

$ git commit --amend

The instructions I followed to do this can be found here: https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages 可以在以下位置找到我遵循的说明: https : //git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

I use Atom, so Atom opens with ' IN correct commit message' displayed, which I change to 'Correct commit message' and save my changes. 我使用Atom,因此Atom打开时显示“ IN正确提交消息”,我将其更改为“正确提交消息”并保存我的更改。

After I saved the altered commit message, I did a $ git log -1 expecting to see 'Correct commit message'; 保存更改后的提交消息后,我执行了$ git log -1期望看到“正确的提交消息”; however, I still see ' IN correct commit message.' 但是,我仍然看到“ IN正确的提交消息”。

What exactly am I doing wrong? 我到底在做什么错?

Note 注意

Just prior to this, I changed my git editor from Sublime to Atom following these instructions: How do I make Git use the editor of my choice for commits? 在此之前,我按照以下说明将git编辑器从Sublime更改为Atom: 如何让Git使用所选的编辑器进行提交?

I basically used: 我基本上使用:

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

and

$ export GIT_EDITOR=atom

I realize now that I didn't have to do both, but I also realize this probably didn't hurt either. 现在,我意识到我不必同时执行这两项操作,但是我也意识到这可能也没有伤害。

There were two things that fixed this for me. 件事为我解决了这个问题。

One

As @torek pointed out in his comment attached to my original post, setting the --wait argument when invoking Atom blocks git from returning from the $ git commit --amend command. 正如@torek在我的原始文章所附的评论中所指出的那样,在调用Atom时阻止用户从$ git commit --amend命令返回时设置--wait参数。 Apparently, this is necessary for git to successfully capture the altered commit message, rather than returning before the message has even been altered. 显然,这对于git成功捕获更改的提交消息是必要的,而不是在消息被更改之前返回。 Makes sense. 说得通。

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

Two

Apparently, if I did not explicitly save my altered commit message (command + s on mac), it would never get saved. 显然,如果我没有明确保存更改后的提交消息(在Mac上为command + s),则将永远无法保存该消息。 This I had to do in order to get the commit message to recognize my altered commit message. 为了获得提交消息以识别更改的提交消息,我必须这样做。

This might seem pretty obvious at first; 起初这似乎很明显。 however, if I altered my commit message and clicked the close window button ('x' at the top-left of the window on mac), something strange would happen... 但是,如果我更改了提交消息并单击了关闭窗口按钮(在Mac窗口的左上角为“ x”),则会发生一些奇怪的事情……

If I altered my commit message, close Atom using the close window button ('x'), and then subsequently execute a $ git log -1 command, the commit message would show the original unaltered commit message. 如果更改了提交消息,请使用关闭窗口按钮('x')关闭Atom,然后执行$ git log -1命令,该提交消息将显示原始的未更改提交消息。 Nothing strange there. 那里没什么奇怪的。

However, if I then executed another $ git commit --amend command , Atom would open and display the altered commit message from the previous $ git commit --amend command! 但是, 如果我随后执行另一个 $ git commit --amend 命令 ,则Atom将打开并显示上一个 $ git commit --amend 命令 更改后的提交消息 This is very strange behavior if you ask me. 如果您问我,这是非常奇怪的行为。 Not being a git guru, lets just say this didn't clear up any confusion for me. 不是一名git大师,可以说这并没有消除我的任何困惑。

Bottom line 底线

Append the --wait argument ( $ git config --global core.editor "atom --wait" ), and explicitly save your altered commit message in Atom (command + s on mac) when performing a $ git commit --amend . 附加--wait参数( $ git config --global core.editor "atom --wait" ),并在执行$ git commit --amend时将更改的提交消息显式保存在Atom中(在Mac上为Command + s)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM