如何清除git仓库的所有提交记录,成为一个新的干净仓库

转载自:https://blog.csdn.net/icansoicrazy/article/details/128342811

操作步骤

1. 切换到新的分支
git checkout --orphan latest_branch

git checkout --orphan 核心用途:以类似git init的状态创建新的非父分支,即创建一个没有提交记录的分支。

2. 缓存所有文件(除了.gitignore中声明排除的)
git add -A
3. 提交跟踪过的文件(Commit the changes)
git commit -am "commit message"
4. 删除master分支(Delete the branch)
git branch -D master
5. 重命名当前分支为master(Rename the current branch to master)
git branch -m master
6. 提交到远程master分支(Finally,force update your repository)
git push -f origin master
posted @   Felix_Openmind  阅读(484)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
*{cursor: url(https://files-cdn.cnblogs.com/files/morango/fish-cursor.ico),auto;}
点击右上角即可分享
微信分享提示