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.
ORIGINAL did fork but search didn't helped me
Whheew, I thought I had lost some big changes in a local project. I wanted to change the commit msg, but forgot how (git commit --amend)
This function removes all the changes too! If you do this and want your commit back, you can do the following:
git reflog
<- This will show all the changes you made, including the commit hash of the commit you removedgit reset --hard COMMIT_HASH
<- will restore your changesCredits to: https://stackoverflow.com/a/21778