如果需要 Git 仓库只保留 1 条 commit,您可以:
- 首先,使用命令
git checkout的--orphan选项创建一个空白分支(本文为temporary):git checkout --orphan temporary - 添加当前目录下所有文件:
git add . - 提交 commit 到 Git 仓库(本文的 commit 信息为
Initial commit):git commit -m "Initial commit" - 删除只保留 1 条 commit的分支(本文为
main):git branch -d main - 重命名当前分支为只保留 1 条 commit的分支(本文为
main):git branch -m main - 最后,强制推送到 Git 仓库:
完成!git push -f
相关文章: