What is the git commands to delete unwanted commits that haven't been pushed to the remote?

If I have a few local topic branches I have made commits on and haven’t yet pushed them to the remote, how can I delete them?

I don’t want to pollute the main tree with unwanted commits.

  • What is the dummy's way to work on wordpress locally (w/versioning) and migrate changes to server, including databases?
  • Git version is different between remote and local copy
  • Mac Os X - Xcode4 and remote git-repository (and a local repository on the Mac)
  • How to remove a file from git repo on local and remote
  • How Can I Seamlessly Use A Local Bower Dependency?
  • Can I change the default directory on my local drive for all Git activity?
  • Eclipse: How to export local history to a real SCM system like Git or SVN
  • How to make changes that only i can see?
  • 3 Solutions collect form web for “What is the git commands to delete unwanted commits that haven't been pushed to the remote?”

    If you haven’t yet pushed them to the remote, it should be easy to delete them.

    git branch -D <branch-to-delete>
    

    will forcibly delete a branch that you don’t want to keep.

    Try looking up rebase- there is a good series of videos here: http://www.ava.co.uk/git

    Try this one. This way it’s possible to drop single commit. I assume the commit you want to drop is no further than 16 steps back from the HEAD.

    git rebase -i HEAD~16...HEAD

    Git Baby is a git and github fan, let's start git clone.