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.
If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^
which will evict the commits from the branch and from the index, but leave the working tree around.
If you want to save the commits on a new branch name, then run git branch newbranchname
before doing the git reset.
@Newbclharri
git push origin -f
means the same as--force
, it means it will push, even when the history doesn't match, or even when you have DELETED commits. Do not run this command unless you understand what it does, and even then, always prefer--force-with-lease
, that way if two people were to run the same command at the same time, it would prevent the second person being able to accidentally overwriting and thusremoving
your commits from the branch.