1

I made a mistake and so I needed to undo the last commit.

The usual steps are:

git reset --soft HEAD~
// make changes...
git commit -c ORIG_HEAD

However I did this by accident:

git reset --soft HEAD~
// make changes...
git commit -m "Some new message"     // <-- shouldn't have done this!!

Is it equivalent? If not, what are the implications, and how can I (should I?) "undo the undo"?

Community
  • 1
  • 1
h bob
  • 3,610
  • 3
  • 35
  • 51
  • 1
    Both of your scenarios will create a commit, but in the first case you would simply reuse the log and author information from `ORIG_HEAD`. To be clear, functionally speaking both make the same commit. If you don't want that commit, revert it or nuke it. – Tim Biegeleisen Jul 22 '16 at 07:16
  • @TimBiegeleisen If they are the same, and I keep it as is, then what happens to that special `ORIG_HEAD` because I didn't use it (and I assume if I had done things properly, it would have been deleted). Or put differently, if I need to undo again in the future, will the existence of that be a problem? – h bob Jul 22 '16 at 07:21

1 Answers1

1

The difference between your way and the way described in the original forum post is that you create a new commit with a new author and information. But since you are the old committer anyways nothing of this will change if you do not change the message either.

If you want to delete the ORIG_HEAD you can do it with the following command:

rm -f $GIT_DIR/ORIG_HEAD
# or
rm -f .git/ORIG_HEAD

It wont do you any harm having it there, but it might be good to remove it since it does no good there. If you were to do a similar action it would just simply be overwritten by the new ORIG_HEAD.

Englund
  • 1,067
  • 7
  • 13
  • Should I delete `ORIG_HEAD` somehow? In case I need to "undo" again at some point in the future. – h bob Jul 22 '16 at 07:37
  • "...it would just simply be overwritten..." yeah that's what I thought, but wasn't sure. Thanks. – h bob Jul 22 '16 at 08:30