清除git仓库历史记录
在用git与github对作业进行管理的时候犯了很多的错误(其实就是单纯蠢),于是导致仓库的历史记录又臭又长,所以打算把历史记录全部清除并且让目前所有文件全部变成首次 commit 的转态。于是在Stack Overflow上找到了这个方法。
Checkout
# orphan参数用于创建没有commit记录的分支
$ 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 main
Rename the current branch to master
$ git branch -m main
Finally, force update your repository
$ git push -f origin main
历史记录清除后自然无法回滚,不过目前这个仓库算是完成了它的使命,就算要修改也只需要在现在基础上修改。

浙公网安备 33010602011771号