Blankman Blankman - 1 month ago 18
Git Question

Rollback to last git commit

I just did a

git commit -m "blah"


then I added some files, how do I rollback and remove what is in my current files that have not yet been added/committed?

Answer

The below ORIGINAL answer is what I "think" the OP was looking for. Although, per a comment by @ChrisNevill, the original answer may not be what YOU are looking for. I've updated the answer to clarify.


→ UPDATED ANSWER

1) To UNDO local file changes but NOT REMOVE your last commit, then use

git reset --hard

2) To UNDO local file changes AND REMOVE your last commit, then use

git reset --hard HEAD^
or
git reset --hard HEAD~

3) To KEEP local file changes and REMOVE ONLY your last commit, then use

git reset --soft HEAD^
or
git reset --soft HEAD~

Use git status and git log frequently to observe your current state.


→ ORIGINAL ANSWER

"Reset the working tree to the last commit"

git reset --hard HEAD^   

"Clean unknown files from the working tree"

git clean