1

Sometimes I start a project on github. I will make say around 100 commits and now I am ready to tweet about it. I want to have a clean commit history. So I delete the project and start a new project. Sometimes I would rollback all the previous commits and then will add one commit with final output.

How do I undo all the previous commits and then have just one commit with final output.

Nick Vanderbilt
  • 36,724
  • 29
  • 83
  • 106

2 Answers2

6

100 commits is great to start with! There's no reason to throw away that history and start over with a "clean" commit history. Your commit history will never stay clean, so there's no point in trying to clean it up now.

The only reason to go back and rewrite old commits is if you accidentally committed a password or some other secret into your code history. Otherwise, your project commit log reflects what actually happened, which is a good thing.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • Agreed. @Nadal, keep the history you already have. Clean up any confidential bits if you need to, but leave the rest intact. Neither the code, nor its history will ever be perfect. – Chris Johnsen Dec 13 '10 at 02:52
  • +1, available history is good! You should not be afraid of showing the mistakes you made and corrected :) – Gauthier Dec 15 '10 at 09:26
4

One way to do this, assuming that no one has already forked your repository (or you don't care if they have), is to git rebase -i and squash all commits back down a single commit.

Or you could do an export: Do a "git export" (like "svn export")?

Or you could rm -rf .git and then git init to get a new repo with the same files.

Community
  • 1
  • 1
Adam Vandenberg
  • 19,991
  • 9
  • 54
  • 56