Skip to content

Instantly share code, notes, and snippets.

@cutiko
Created November 22, 2019 18:24
Show Gist options
  • Star 40 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save cutiko/0b1615c63504a940877541362cc51211 to your computer and use it in GitHub Desktop.
Save cutiko/0b1615c63504a940877541362cc51211 to your computer and use it in GitHub Desktop.
Git delete last commit

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

@anton-x-t
Copy link

mine says (more?) what should i do

A quick google on git reset more showed me the answer. Google is your friend @abdolmaleamir .

You should probably do git reset HEAD~1.

Google link

Solution credit: thank you Adam Dymitruk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment