使用 `git rebase` 更改旧的提交消息 [英] Change old commit message using `git rebase`

查看:97
本文介绍了使用 `git rebase` 更改旧的提交消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编辑旧的提交消息,如此处所述.

问题是,当我尝试运行 rebase -i HEAD~5 时,它说 interactive rebase already started.

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

error: Refs/heads/master 在 7c1645b447a8ea86ee143dd08400710c419b945b 但预期为 c7577b53d05c91026b9906b6d29c1cf44117d致命:无法锁定引用refs/heads/master".

有什么想法吗?

解决方案

它说:

<块引用>

当您保存并退出编辑器时,它会将您倒回到该列表中的最后一次提交,并让您进入命令行并显示以下消息:

$ git rebase -i HEAD~3停在 7482e0d... 更新了 gemspec 以希望能更好地工作您现在可以修改提交,使用

这并不意味着:

<块引用>

再次输入git rebase -i HEAD~3

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


正如 Dave Vogt 在评论中提到的那样,git rebase --continue在您修改第一个提交之后,用于在 rebase 过程中转到下一个任务.

此外,Gregg Lind他的回答 git rebase:

<块引用>

通过替换命令pick"使用命令edit",您可以告诉 git rebase 在应用该提交后停止,以便您可以编辑文件和/或提交消息、修改提交并继续重新设置基准.

如果您只想编辑提交的提交消息,请替换命令pick";使用命令reword",因为 Git1.6.6(2010 年 1 月).

它与edit"在交互式变基期间所做的相同,除了它只允许您编辑提交消息而无需将控制权返回给 shell.这非常有用.
目前,如果您想清理提交消息,您必须:

$ git rebase -i next

<块引用>

然后将所有提交设置为编辑".然后每一个:

# 在编辑器中更改消息.$ git commit --amend$ git rebase --continue

<块引用>

使用 'reword' 而不是 'edit' 可以让您跳过 git-commitgit-rebase 调用.

I was trying to edit an old commit message as explained here.

The thing is that now, when I try to run rebase -i HEAD~5 it says interactive rebase already started.

So then I try: git rebase --continue but got this error:

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

Any ideas?

解决方案

It says:

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

It does not mean:

type again git rebase -i HEAD~3

Try to not typing git rebase -i HEAD~3 when exiting the editor, and it should work fine.
(otherwise, in your particular situation, a git rebase -i --abort might be needed to reset everything and allow you to try again)


As Dave Vogt mentions in the comments, git rebase --continue is for going to the next task in the rebasing process, after you've amended the first commit.

Also, Gregg Lind mentions in his answer the reword command of git rebase:

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 rebase` 更改旧的提交消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆