Git 只保留1条 commit
如果需要 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
完成!
相关文章: