Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mikeon/f19ddb5e87c47779d3c0434d3573c3ea to your computer and use it in GitHub Desktop.

Select an option

Save mikeon/f19ddb5e87c47779d3c0434d3573c3ea to your computer and use it in GitHub Desktop.

Revisions

  1. @CrookedNumber CrookedNumber created this gist Feb 12, 2014.
    7 changes: 7 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    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.