简体   繁体   English

如何更改尚未推送的倒数第二个提交消息

[英]How to change second last commit message which is not pushed yet

I usually submit a list of commits for review.我通常会提交一份提交清单以供审查。 If I have the following commits:如果我有以下提交:

 HEAD (not pushed) Commit1 (not pushed) (Merged master here) Commit2 Commit3 ...

I know that I can modify head commit with git commit --amend.我知道我可以使用 git commit --amend 修改头部提交。 But how can I modify Commit1?但是如何修改 Commit1? given that it is not the HEAD commit and not pushed.鉴于它不是 HEAD 提交而不是推送。 git rebase does not show it in list of I enter git rebase -i HEAD~3. git rebase 没有显示在我输入 git rebase -i HEAD~3 的列表中。

Thank you for the answers, Actually the commit message I wanted to modify was merge commit and git rebase command does not show merge commits(if not pushed I guess) in rebase HEAD~n command and it was the main issue.感谢您的回答,实际上我想修改的提交消息是合并提交,而 git rebase 命令不会在rebase HEAD~n命令中显示合并提交(如果没有推送我猜),这是主要问题。

With the help of my colleague I was able to resolve by this command在我同事的帮助下,我能够通过这个命令解决

git rebase -i -p HEAD~3 git rebase -i -p HEAD~3

where -p is for preserve merges Still not able to understand how this works fully, but it did the job. -p 用于保留合并仍然无法理解这是如何完全工作的,但它完成了这项工作。

If you:如果你:

You can use git filter-repo and its callbacks , based on the content of the old message:您可以根据旧消息的内容使用git filter-repo 及其回调

git-filter-repo --message-callback '
  if b"known content" in message:
    message = "New message\npossibly on\n several lines""
  return message'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM