How can I delete all my commits without erasing the documents and push it as one commit?
Asked
Active
Viewed 89 times
2
-
do you mean [git squash](https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git)? – Narro Oct 27 '20 at 09:24
-
https://stackoverflow.com/q/9683279/7976758, https://stackoverflow.com/search?q=%5Bgit%5D+delete+all+commits – phd Oct 27 '20 at 12:14
2 Answers
3
There are several options, one of them is :
git reset --soft <sha1 of first commit in your repo>
git commit --amend

LeGEC
- 46,477
- 5
- 57
- 104
0
@LeGEC's answer is probably the 'right' way to do it, but another option is to simply delete your .git
folder and re-run git init
, which will totally reinitialise your repository. You can then git add -A
and git commit -m <message>
, but you'll need to git remote add <remote-name> <remote-link>
again before you git push <remote-name> <branch-name>
. This also assumes you weren't doing much with branching. If you simply had one default branch master
, then all's well, but e.g. if you'd renamed it (say, to main
), then you'll need to do that again before pushing. If you had more complex branching, then this is probably not the best approach, unless you also want to reset that.

Bertie Wheen
- 76
- 4