Help, I want to undo my last commit but keep the changes
Take back the last commit and keep every change in it, ready to fix up and commit again.
The fix
git reset --soft HEAD~1The commit is gone from the branch, and all its changes are staged again. Edit, then commit when ready.
git revert --no-edit HEADAdds a commit that undoes the last one, without rewriting anything your team already has.
git pushShare the undo.
git cherry-pick --no-commit a1b2c3dUse the hash of the commit you reverted: its changes come back as staged work, so you can keep going.
a1b2c3d is an example. Replace it with your own.
git reset --soft HEAD~1Why this works
reset --soft only moves the branch back one commit. Your files and the staging area stay exactly as they were, so the changes from that commit are simply staged again. Once a commit is pushed, moving the branch back would pull the rug from under everyone who has it. revert instead adds a new commit that undoes it, and cherry-pick --no-commit brings the changes back into your working copy to keep working on.