How to un-commit the last n commits?
I’m working on a tree which has the following commits:-
aaaaaaa Implement function A bbbbbbb Implement function B ccccccc Implement function C
I would like to un-commit the first two , that is , to put these changes again into the staging area. I’ve learnt that
git reset --soft HEAD^ would un-commit the last commit. But I would like to know the way to do it for many commits at once. I’m not sure if
git reset --soft HEAD~10 would un-commit the 10th from the last commit or un-commit the last 10 commits.
One Solution collect form web for “How to un-commit the last n commits?”
First, be sure that none of the commits you’re trying to change have been pushed to the public repository. (From the sounds of it, they have not yet been made public.)
You’re on the right track with
git reset --soft HEAD^.
HEAD^is one commit before HEAD.
HEAD~4is four commits before HEAD – or, altogether, five commits back.
Found on GitHub blog