清空git提交记录

264 阅读1分钟

在当前分支中,切换到当前记录,按以下步骤操作:

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

2.缓存所有文件(除了.gitignore中声明排除的)
 git add -A
 
3.提交跟踪过的文件(Commit the changes)
 git commit -m "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
7.關聯遠程倉庫
git remote add origin url地址
8.切换远程仓库到本地:
git checkout -b 本地分支名 origin/远程分支名