4

I load on git some project which contains some personal data. Now I changed all lines and commit it. Now I need to erase all commits except last one to prevent loosing personal data.

Aleksandr
  • 777
  • 6
  • 22
  • The best way is to merge all commits into one, which is answered by this question: http://stackoverflow.com/questions/7425725/how-to-merge-all-previous-commits-into-a-single-commit?rq=1 – Jon Cairns Mar 25 '13 at 14:43
  • finally, I just bought account to hide this code – Aleksandr Apr 23 '13 at 19:36

1 Answers1

11

Given that your main branch is called master, and you want to remove all commits except the last one from your master:

  1. git checkout --orphan tmp
  2. git add . --all
  3. git commit -m "Init."
  4. git push origin tmp
  5. On your remote git repo select tmp as main branch
  6. git branch -D master
  7. git push origin :master
  8. git checkout -b master
  9. git push origin master
  10. On your remote git repo select master as main branch
  11. git branch -D tmp
  12. git push origin :tmp
stevek-pro
  • 13,672
  • 14
  • 81
  • 134