我在承诺信中写错了。

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


当前回答

对于任何正在寻找一个Windows/Mac GUI来帮助编辑旧消息(即不仅仅是最新消息),我会推荐Sourcetree。

此分類上一篇

对于尚未推到远程的承诺:

在“Log/History”选项卡中,右键单击您要编辑的承诺(s)下图中的附属线的输入,并选择“Rebase children of <commit ref> interactively..." 选择您要更改的承诺消息的整个行。

...或......对于已经推出的承诺:

遵循这个答案中的步骤,这些类似于上面的,但需要一个进一步的命令运行从命令线(git push 起源 <branch> -f) 强迫推分。

其他回答

我更喜欢这样:

git commit --amend -c <commit ID>

否则,将有一个新的承诺与一个新的承诺ID。

如果你只想修改你的最后一个承诺消息,那么做: git commit --amend

它会把你推到你的文本编辑器,让你改变最后的承诺消息。

如果您想更改前三個承諾訊息,或任何承諾訊息到這一點,請將 HEAD~3 傳送到 git rebase -i 命令: git rebase -i HEAD~3

使用

git commit --amend

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

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

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 是重写最后一份重写的方式。

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