Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Github commit history

Tags:

git

github

Is there anyway for me to delete my github commit history? I don't want to lose all my commits, just the last 10 or so that were pushed to github. I can't seem to figure out how to do this.

like image 392
Manish Burman Avatar asked Aug 13 '11 05:08

Manish Burman


People also ask

Can you delete GitHub commit history?

If you commit sensitive data, such as a password or SSH key into a Git repository, you can remove it from the history.

How do I remove a commit from git history?

By deleting line of the commit or writing drop instead of pick, you can remove the commit from history. Thus, we deleted a commit locally. To remove it from remote repository, we should push our changes to remote. The + sign before the name of the branch you are pushing, this tells git to force the push.

Can I delete previous commits?

The easiest way to undo the last Git commit is to execute the “git reset” command with the “–soft” option that will preserve changes done to your files. You have to specify the commit to undo which is “HEAD~1” in this case. The last commit will be removed from your Git history.


1 Answers

Just pick the hash you want to go back to and in your clone do:

git reset --hard hash#  git push -f origin branch 

where branch is the name of the branch you want to push. Voilà. Be carefully with the force push. You may want to copy your working directory until you are familiar with it.

like image 116
matthewdaniel Avatar answered Sep 20 '22 12:09

matthewdaniel