git - 使用 `git rebase` 更改旧提交消息

标签 git repository rebase git-rebase

我正在尝试按照说明编辑旧的提交消息 here .

现在,当我尝试运行 rebase -i HEAD~5 时,它说 interactive rebase already started

然后我尝试:git rebase --continue 但是得到这个错误:

error: Ref refs/heads/master is at 7c1645b447a8ea86ee143dd08400710c419b945b but expected c7577b53d05c91026b9906b6d29c1cf44117d6ba
fatal: Cannot lock the ref 'refs/heads/master'.

有什么想法吗?

最佳答案

它说:

When you save and exit the editor, it will rewind you back to that last commit in that list and drop you on the command line with the following message:

$ git rebase -i HEAD~3
Stopped at 7482e0d... updated the gemspec to hopefully work better
You can amend the commit now, with

这并不意味着:

type again git rebase -i HEAD~3

尝试在退出编辑器时不要输入git rebase -i HEAD~3,它应该可以正常工作。
(否则,在您的特定情况下,可能需要 git rebase -i --abort 来重置所有内容并允许您重试)


作为Dave Vogt在评论中提到,git rebase --continue 用于在 rebase 过程中进行下一个任务,在您修改了第一个提交之后

此外,Gregg Lindhis answer 中提到git rebasereword 命令:

By replacing the command "pick" with the command "edit", you can tell git rebase to stop after applying that commit, so that you can edit the files and/or the commit message, amend the commit, and continue rebasing.

If you just want to edit the commit message for a commit, replace the command "pick" with the command "reword", since Git1.6.6 (January 2010).

It does the same thing ‘edit’ does during an interactive rebase, except it only lets you edit the commit message without returning control to the shell. This is extremely useful.
Currently if you want to clean up your commit messages you have to:

$ git rebase -i next

Then set all the commits to ‘edit’. Then on each one:

# Change the message in your editor.
$ git commit --amend
$ git rebase --continue

Using ‘reword’ instead of ‘edit’ lets you skip the git-commit and git-rebase calls.

关于git - 使用 `git rebase` 更改旧提交消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1884474/

相关文章:

android - 将 facebook-android-sdk 导入 Eclipse 有困难

git:如何查看分支中所做的更改

docker - 如何从 Docker Hub 中删除存储库

git - 致命的 : Not a git repository (or any of the parent directories): . git

git - 如何防止某些分支的 rebase ,例如 'master'

git - 压缩推送的 Git 提交的最佳实践是什么

git - 将远程分支提示从一个分支移动到另一个分支

git - 如何列出已删除的 github 分支

Git 完全重置。删除所有文件。删除历史记录

c# - 我应该如何设计我的业务层来根据配置设置处理 Sql Server 和 Mongo DB