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.
Remove last commit from GitHub
First way
Another way
Both ways works fine.
Return removed commit to GitHub
Step 1. Find full SHA of deleted commit
Step 2. Recover the dangling commit with rebase
Deleted in this way commit still in git reflog. But garbage collector should remove typically in 30 days or so.
This was created thanks to you as a summary of the topic.
Thank you all.