Change old commit message on Git

后端 未结 5 1127
南旧
南旧 2020-12-12 09:24

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 rebas

5条回答
  •  心在旅途
    2020-12-12 09:46

    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.

提交回复
热议问题