I have a repository.
How can I delete my old commits via terminal? My SSH key is uploaded.
(I'm using github pages, that's why version tracking is not important, don't want to waste Github's storage)
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this communityI have a repository.
How can I delete my old commits via terminal? My SSH key is uploaded.
(I'm using github pages, that's why version tracking is not important, don't want to waste Github's storage)
Deleting the .git
folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:
Checkout
git checkout --orphan latest_branch
Add all the files
git add -A
Commit the changes
git commit -am "commit message"
Delete the branch
git branch -D master
Rename the current branch to master
git branch -m master
Finally, force update your repository
git push -f origin master
PS: this will not keep your old commit history around.
You have an really good answer for that here: https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github
And I quote
Note: please see alternative to
git rebase -i
in the comments below—
git reset --soft HEAD^
First, remove the commit on your local repository. You can do this using
git rebase -i
. For example, if it's your last commit, you can dogit rebase -i HEAD~2
and delete the second line within the editor window that pops up.Then, force push to GitHub by using
git push origin +master
.See Git Magic Chapter 5: Lessons of History - And Then Some for more information (i.e. if you want to remove older commits).
Oh, and if your working tree is dirty, you have to do a
git stash
first, and then agit stash apply
after.
Hope this help you :)
==== EDIT ====
Actually I just reread the post I linked to and specially the comment "word of caution 2" https://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github
From that I learned that git seems create a new commit and moving the pointer to it, rather than deleting it when using force push. That is if someone already have the SHA1 of your commit, they can still access it. So when taking this into consideration, I must recommend that you do as Tomasz Klim suggested.