Unable to delete commit history of repository

I tried deleting the commit history of my repository on github. I found instuctions on doing this at the link below :

To this date I have been unsuccessful. I was forced to make the repository private.

any help will be appreciated

There are so many scenarios on deleting history; what exactly are you trying to do?

Deleting last 3 commits? Are they pushed to remote?

Deleting a specific commit back in history 5 commits back from HEAD?

Last I recall, this site was useful walking someone through several scenarios. Disclaimer it’s been several years since I’ve tried this out, but it should be accurate.

Hope that helps!

As @bretonics mentioned, there are many ways to go about.

I personally find that the simplest way is apply all the changes you want and then squash all commits together, which results in the repository history being re-written as there was ever only just on commit, you then only need to git push --force and the new history will be forced on the GitHub repository — beware that all previous commits will be lost with this operation, so consider it an irreversible operation (although there are ways to undo this via the Reflog).

As the article you linked mentions, rewriting history on the main branch of a repository is usually a bad idea.

If by “deleting” you mean resetting the repository to a pristine state (as if it was a new one, without history), then you only need to delete all contents (including the .git/ folder), execute git init, add again the remote pointing to your GitHub origin, and force push — this way it would be as you had just created the repository now.

Deleting the complete commit history of the repository except for the very last commit.

There currently 16 commits total in the repository.

Just do an interactive rebase of the whole history and make them all fix ups to a single commit. Then force push it.

1 Like

can you give me an example on how to do this?

Here’s some docs that should help, the first one is eclipse/eGit specific but may still help you to understand the process:

https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History