如何使用 rebase 编辑推送的提交消息?
How to edit a pushed commit message using rebase?
我正在努力弄清楚如何编辑已推送到 GitHub 的 git 提交消息。我可以发誓,在过去我曾使用过相同的命令来编辑已经推送的 git 提交并且没有任何问题。我现在遇到的问题是当我 运行 git rebase --interactive <SHA of commit>
我得到看起来像这样的东西...
noop
# Rebase 5d8e041..5d8e041 onto 5d8e041 (1 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
当我 运行 执行完全相同的命令但带有 git 尚未推送到 GitHub 的提交时,一切正常。有什么我想念的吗?就像我之前说过的那样,我可以发誓,这一次在推送和未推送的提交上都工作得很好。
非常感谢你的帮助我非常感谢。
如documented here, a "reword" will allow you to change a past commit message (provided you rebase on top of the parent commit you want to change, as first reported in -- upvoted -- nnovich-OK's ).
但是如果提交已经被推送到 GitHub,您将必须执行 git push --force
(or --force-with-lease
, if )
When I run git rebase -i 5d8e041~1
I got Current branch master is up to date
检查 addinf the --force
option 是否有帮助。
您需要 select 父级 提交的散列,而不是您要更改的提交。
因此,如果您的 git 日志如下所示:
$ git log --oneline
5cd3b9a (HEAD -> master) Hi I'm John, I'm a bad commit message
b6266a5 Hi, I'm the parent of John
j45cj33 And I'm the grand parent of John
...
基于 parent 提交:
git rebase --interactive b6266a5
然后将单词pick
改为reword
。当您保存并退出时,将打开一个新的编辑器,允许您更改提交消息。
要更新 github,您必须使用 force。如果你的分支被称为 master,那么这样做:
$ git push --force origin master
请记住,这将重写 github 上的历史记录。如果你在某人已经从 github 中拉出后重写历史,你会自找麻烦。
问题与 pushed/not-pushed 提交状态无关。您正在尝试准确编辑分支上的最后一次提交。要通过 rebase 做到这一点,你应该调用 git rebase --interactive <SHA of PARENT commit>
,但你使用提交本身的散列代替。 Rebase 应该编辑指定提交的所有后代,但您提供的提交没有后代,因此 git 在可能的更改列表中显示 noop
。
顺便说一句,可以使用 git commit --amend
轻松编辑最后一次提交,试试吧。
我的问题的最终答案是 git rebase -i <sha>
没有调出首选编辑器来选择是否 reword
提交消息或任何其他选项。答案是我使用的是 64bit
架构而不是 32bit
架构。现在,老实说,我不知道这是为什么,但我确实在 GitHub 上找到了一个 post,它在谈论某些命令在 64bit
架构上失败,特别是 git rebase
和根据 post 的某些 git merge
操作。还说...
leaves incomplete git operation and also adds a file on disk, sh.exe.stackdump with STATUS_STACK_OVERFLOW + register dump.
虽然我没有在 git 控制台中弹出此错误。当我在 SmartGit 中打开我的项目时,它只是 git 的一个 GUI。当我右键单击 git 提交消息之前的 git 消息时,我实际上想要变基然后转到 Rebase Interactive From
,就会发生这种情况。它不会立即通过错误,而是会尝试 10 秒,然后通过错误。
所以在这一点上,我已经弄清楚是什么导致了我的问题,但我还不知道为什么。为什么 git 运行 的 64bit
体系结构版本与 32bit
不同?头脑难以置信。如果有人有发生这种情况的具体原因,请继续并编辑我的 post.
我正在努力弄清楚如何编辑已推送到 GitHub 的 git 提交消息。我可以发誓,在过去我曾使用过相同的命令来编辑已经推送的 git 提交并且没有任何问题。我现在遇到的问题是当我 运行 git rebase --interactive <SHA of commit>
我得到看起来像这样的东西...
noop
# Rebase 5d8e041..5d8e041 onto 5d8e041 (1 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
当我 运行 执行完全相同的命令但带有 git 尚未推送到 GitHub 的提交时,一切正常。有什么我想念的吗?就像我之前说过的那样,我可以发誓,这一次在推送和未推送的提交上都工作得很好。
非常感谢你的帮助我非常感谢。
如documented here, a "reword" will allow you to change a past commit message (provided you rebase on top of the parent commit you want to change, as first reported in -- upvoted -- nnovich-OK's
但是如果提交已经被推送到 GitHub,您将必须执行 git push --force
(or --force-with-lease
, if
When I run
git rebase -i 5d8e041~1
I gotCurrent branch master is up to date
检查 addinf the --force
option 是否有帮助。
您需要 select 父级 提交的散列,而不是您要更改的提交。
因此,如果您的 git 日志如下所示:
$ git log --oneline
5cd3b9a (HEAD -> master) Hi I'm John, I'm a bad commit message
b6266a5 Hi, I'm the parent of John
j45cj33 And I'm the grand parent of John
...
基于 parent 提交:
git rebase --interactive b6266a5
然后将单词pick
改为reword
。当您保存并退出时,将打开一个新的编辑器,允许您更改提交消息。
要更新 github,您必须使用 force。如果你的分支被称为 master,那么这样做:
$ git push --force origin master
请记住,这将重写 github 上的历史记录。如果你在某人已经从 github 中拉出后重写历史,你会自找麻烦。
问题与 pushed/not-pushed 提交状态无关。您正在尝试准确编辑分支上的最后一次提交。要通过 rebase 做到这一点,你应该调用 git rebase --interactive <SHA of PARENT commit>
,但你使用提交本身的散列代替。 Rebase 应该编辑指定提交的所有后代,但您提供的提交没有后代,因此 git 在可能的更改列表中显示 noop
。
顺便说一句,可以使用 git commit --amend
轻松编辑最后一次提交,试试吧。
我的问题的最终答案是 git rebase -i <sha>
没有调出首选编辑器来选择是否 reword
提交消息或任何其他选项。答案是我使用的是 64bit
架构而不是 32bit
架构。现在,老实说,我不知道这是为什么,但我确实在 GitHub 上找到了一个 post,它在谈论某些命令在 64bit
架构上失败,特别是 git rebase
和根据 post 的某些 git merge
操作。还说...
leaves incomplete git operation and also adds a file on disk, sh.exe.stackdump with STATUS_STACK_OVERFLOW + register dump.
虽然我没有在 git 控制台中弹出此错误。当我在 SmartGit 中打开我的项目时,它只是 git 的一个 GUI。当我右键单击 git 提交消息之前的 git 消息时,我实际上想要变基然后转到 Rebase Interactive From
,就会发生这种情况。它不会立即通过错误,而是会尝试 10 秒,然后通过错误。
所以在这一点上,我已经弄清楚是什么导致了我的问题,但我还不知道为什么。为什么 git 运行 的 64bit
体系结构版本与 32bit
不同?头脑难以置信。如果有人有发生这种情况的具体原因,请继续并编辑我的 post.