Git: simplest way of squashing commits on master

Possible Duplicate:
How can I squash my last X commits together using git?

I have a project hosted on GitHub and I have a local clone. I have a load of small commits that I have already pushed up to GitHub. This has all been done using the default *master branch.

  • What is the advantage of using git submodules over having a repo inside another repo with a gitignore?
  • Multiple github accounts: what values for Host in .ssh/config?
  • Why do I get “unable to connect a socket” when I try to clone via a git URL?
  • Search and replace text in all files of Git repo
  • Is it possible to remove all the commits of a specific user?
  • Replace one project with another on git repository
  • I got confused between merge –squash and rebase etc…
    What is the most straightforward way of combining several historial commits in to one commit so that it pushes up to GitHub?

  • Source Tree and Github not seeing all of my files
  • How does one disable vc-git in emacs?
  • What is the purpose of Perforce file “.perforce”?
  • Setting environment variable through SSH git push
  • How does git bisect skip choose the next commit to try?
  • How to remove selected commit log entries from a Git repository while keeping their changes?
  • One Solution collect form web for “Git: simplest way of squashing commits on master”

    Before starting, you should make sure that git status is clean (i.e. there’s no output from that command) to avoid losing work. The simplest way to do what you want is probably:

    git reset --soft <LAST-COMMIT-THAT'S-OK>
    git commit -m 'Many squashed commits'
    git push --force origin master
    

    You should bear in mind that this is rewriting history (that’s why you need the --force option to git push) so you should avoid this if anyone else might have cloned or pulled from your repository. For some more alternatives, see this question and its answers:

    • Squash my last X commits together using Git
    Git Baby is a git and github fan, let's start git clone.