如何删除github中的所有提交历史? [英] how to delete all commit history in github?

查看:67
本文介绍了如何删除github中的所有提交历史?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除所有提交历史,但将代码保持在当前状态,因为在我的提交历史中,有太多未使用的提交.

I want to delete all commit history but keep the code in its current state because, in my commit history, there are too many unused commits.

我该怎么做?

有没有git命令可以做到这一点?

Is there any git command can do this?

git filter-branch ?
git rebase ?
... 

我的代码托管在 github.com 上.

My code is hosted on github.com.

推荐答案

删除 .git 文件夹可能会导致 git 存储库出现问题.如果您想删除所有提交历史记录,但将代码保持在当前状态,那么这样做是非常安全的,如下所示:

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:

  1. 结帐

git checkout --orphan latest_branch

添加所有文件

git add -A

提交更改

git commit -am 提交消息"

删除分支

git branch -D main

将当前分支重命名为 main

Rename the current branch to main

git branch -m main

最后,强制更新你的仓库

Finally, force update your repository

git push -f origin main

PS:这不会保留您旧的提交历史

PS: this will not keep your old commit history around

这篇关于如何删除github中的所有提交历史?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆