xxxxxxxxxx
git checkout . #This will get rid of all uncommited change
xxxxxxxxxx
git log
commit 101: bad commit # Latest commit. This would be called 'HEAD'.
commit 100: good commit # Second to last commit. This is the one we want.
To restore everything back to the way it was prior to the last commit, we need to reset to the commit before HEAD:
git reset --soft HEAD^ # Use --soft if you want to keep your changes
git reset --hard HEAD^ # Use --hard if you don't care about keeping the changes you made
xxxxxxxxxx
git reset --hard branch_name #Reverts all modified files to last commit on branch
xxxxxxxxxx
# Option 1: Create a new commit that undoes the last commit
git revert HEAD
# Option 2: If you need to undo a specific commit by its hash
git revert <commit-hash>
# Option 3: If you need to undo multiple commits
git revert HEAD~3..HEAD # Reverts the last 3 commits