git - 如何修改第二个最新提交

标签 git github

我知道您可以执行 git --amend 来更改最新提交的提交消息。但是如何更改第二个最新的提交消息?这是我的提交现在的样子:

commit eca1b2db14da8ace66aed172056c6e7aaf323093
Author: Adam Sandler
Date:   Fri Jul 13 18:00:13 2012 -0700

    Pre-final work on appending new items on top

commit 7d21bbfea24cb72eafbe0213cad6339354078a81
Author: Adam Sandler
Date:   Fri Jul 13 11:57:40 2012 -0700

    Pre-final work on appending new item on top.

    Loading more  when user reaches the end of the scroll view

我想更改其中包含两条消息的提交 7d21bbfea24cb72eafbe0213ca

最佳答案

似乎在 git 中总是有很多方法可以做事,我不是专家,但这是我在那种情况下所做的:

$ git rebase -i HEAD~2

这会带来一个编辑器,比如:

pick eca1b2d Pre-final work on appending new items on top
pick 7d21bbf Pre-final work on appending new item on top.

下面有一些说明。如果您在要更改其消息的提交上将 pick 更改为 reword,然后保存并退出编辑器,您将打开另一个编辑器,您可以在其中改写提交信息。

我只在尚未推送的提交上执行此操作。如果您已经推送了要更改其消息的提交,您将需要阅读以下内容:How do I recover/resynchronise after someone pushes a rebase or a reset to a published branch?

关于git - 如何修改第二个最新提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11488708/

相关文章:

git - .gitignore 文件不会显示在 Cloud9 文件面板中

php - 当你进行 git Push 时,现有的 apache PHP 进程会发生什么?

ruby-on-rails - 无法推送到 github,ssh : Could not resolve hostname

GitHub:设置 SSH

git - 如何在不接受所有文本更改的情况下让 git 接受模式更改?

git - 如何获取分支的 merge 日志?

linux - 错误 "Failed connect to github.com"

linux - 删除目录内的文件而不是整个目录

git - 防止git推送到错误的远程

android - 如何在 Github 库中添加更改?