Question

I wanted to amend a commit message from two commits ago, so I did:

$ git reset --soft HEAD~1
$ git commit --amend -m "Revised commit message"

Now how do I get HEAD back to where it was before I git reset?

Was it helpful?

Solution

You could just git add -a to stage all the changes you reset and then git commit them, but I think you're going about this all wrong.

If you just want to fix an earlier commit message, you could do the following:

  • git rebase -i HEAD~2

This will rebase your last two commits of the branch, so no code will be changed. Once you do this, you will get a vim (or whatever your default editor is) screen that looks something like this:

pick 2a86f99 commit before that you want to fix
pick 09c407a commit that is at HEAD
  • change the pick in the commit you want to fix to reword:

    reword 2a86f99 commit before that you want to fix pick 09c407a commit that is at HEAD

  • Save and quit (:wq in vim). git will rebase these changes and pause in an editor of the commit message you want to fix. Fix it, save, and quit, and you should be set to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top