Git move latest commit on a branch to stash

42 views Asked by At

When working on a git branch I got some changes in the latest commit. I suspect those changes to be wrong, but not sure. It is easy to remove the commit, and start over.

I want to move that commit to git-stash just incase I need them, and then try another solution on the branch, and still have the option to get the first commit back.

1

There are 1 answers

0
knittl On BEST ANSWER

You don't need a stash in this case, a regular branch works just fine.

git branch backup-my-work
git reset --hard HEAD^

reset --hard HEAD^ will move your branch back by one commit and discard ALL changes in your working tree. Drop the --hard if you want to keep your local changes and the changes of the undone commit (you can then selectively remove the changes from your working tree)