Move (or "Undo") last git commit to unstaged area

Git

Git Problem Overview


What's the best way to move your last git commit back into the "Changes not staged" + "Untracked files" areas (with the commit in question being not-pushed / only in your local repo, effectively removing it from HEAD)?

In other words, how do you roll back a commit, but automatically apply that diff to your unstaged area?

Git Solutions


Solution 1 - Git

You can use git reset to set the current branch to the preceding commit, i.e. HEAD^

git reset HEAD^

Adding --soft will keep those files in the index: (ready to be committed)

git reset --soft HEAD^

> --soft > > (…) This leaves all your changed files "Changes to be committed", as git status would put it.

Solution 2 - Git

git-extras provides a git undo command which is an easier to remember way of doing the same thing (along with a number of other handy extras, as the name implies).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjlbView Question on Stackoverflow
Solution 1 - GitStefanView Answer on Stackoverflow
Solution 2 - GitJohnView Answer on Stackoverflow