I had by mistake pushed hundreds of commits from my local repo to a newly created github repo. How can I clean/remove all these commits on the remote repo so that github repo is clean as it was in the start? I would like also to lose history on those actions. I would like to do that without affecting my local repo.
I cannot delete the branch as it is the github master branch.
You could:
- git clone <your github repo>
- git reset --hard <an_older_commit> (where you didn't have those huge files)
- git push --force origin master
That way:
git gc
on its side periodically, cleaning completely the unreferenced files. However the OP Martin mentions:
how can I do
reset --hard
to the position before the first commit ever?
ie I would like to get the repo empty not to rollback to a previous commit
In that case, create a new local repo, make a first small commit, and push --force
that commit.
More generally, I always try to have a first small initial commit on master branch when creating a repo, in order to be able to get back to a minimal commit, or to start a new branch (for an unrelated development effort) from said minimal commit.
git push -f REMOTE COMMIT:BRANCH
例如,要强制远程origin
的分支master
进行撤消,直到您应该执行ID为123456
的提交
git push -f origin 123456:master
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.