The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

git – How to undo the last commit? – Stack Overflow

Posted by jpluimers on 2016/05/31

Always handy to have at hand as the git-reset documentation is toooooo long:

Undo a commit and redo

$ git commit ...              (1)
$ git reset --soft HEAD~1     (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 “commit”.
  3. Make corrections to working tree files.
  4. Stage changes for 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.

–jeroen

via: git – How to undo the last commit? – Stack Overflow.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.