How do you undo the last commit?


down voteaccepted

Undo a commit and redo

$ git commit -m "Something misspelled"              (1)
$ git reset --soft HEAD~                                    (2)
<< edit files as necessary >>                               (3)
$ git add ...                                               (4)
$ git commit -c ORIG_HEAD                                   (5)
  1. This is what you want to undo
  2. This is most often done when you remembered what you just committed is incomplete, or you misspelled your commit message1, or both. Leaves working tree as it was before git commit.
  3. Make corrections to working tree files.
  4. git add whatever changes you want to include in your new commit.
  5. Commit the changes, reusing the old commit message. reset copied the old head to .git/ORIG_HEADcommit with -c ORIG_HEAD will open an editor, which initially contains the log message from the old commit and allows you to edit it. If you do not need to edit the message, you could use the -C option instead.

Comments

Popular posts from this blog

remove span elements from Contact form 7 but keeping inside elements

Elance HTML5 Test Answers