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.
Removing the last commit To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.
Git uncommit command A hard reset will delete any new files that were added to the index, and undo any updates or changes made to any files that were part of the repository when the last commit occurred. This command typically fulfills the need for a git uncommit command.
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~4
is four commits before HEAD - or, altogether, five commits back.
Found on GitHub blog
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With