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.

  • SVN Question regarding branching and third party vendor branching
  • TFS 2010: How to produce a changelog (ie. list of work items) between two releases of the application using labels?
  • Subversion - should anyone be developing off the trunk?
  • Different default remote (tracking branch) for git pull and git push
  • Trimming Git Commits/Squashing Git History
  • How can I download only the necessary parts of a remote project in Git?
  • Develop on windows, run unicorn in production on heroku
  • Assigning issues to yourself on GitHub
  • my old username is still in use
  • Doctrine migrations: How to avoid SQL errors in the postUp step?
  • set a ftp repository with git
  • When working on a new feature over several days, how do I manage commits?
  • 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.