开发者

How to clean all commits from remote github repo

开发者 https://www.devze.com 2023-03-23 00:08 出处:网络
I had by mistake pushed hundreds of commits from my local repo to a newly created github repo. How can I clean/remove all th开发者_如何学Cese commits on the remote repo so that github repo is clean as

I had by mistake pushed hundreds of commits from my local repo to a newly created github repo. How can I clean/remove all th开发者_如何学Cese 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:

  • Your initial local repo isn't affected (and you can fix it in order to not push again those files)
  • your remote (GitHub) repo doesn't see anymore those commits with the huge files in it.
  • GitHub will run a 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?
i.e. 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

For example, to force the branch master at the remote origin to have undo until the commit with the id 123456 you should do

git push -f origin 123456:master
0

精彩评论

暂无评论...
验证码 换一张
取 消