git清空一个分支所有的commit

创建日期: 2022-08-13 10:45 | 作者: 风波 | 浏览次数: 17 | 分类: Git

参考: - https://www.lmonkey.com/t/WMLDp7VLY - https://blog.csdn.net/lx11573/article/details/126127542


  1. 新建一个空白分支(假设旧分支名字为 master)
git checkout --orphan new_branch

通过 git status 查看当前分支的文件状态,发现文件都为待添加状态,可以选择添加这些文件,也可以直接忽略。

  1. 删除旧本地分支 master
git branch -D master
  1. 将当前新的分支重命名为 master
git branch -m master
  1. 进行强制提交到远程仓库
git push -f origin master

可能遇到的问题

This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.

执行 rm -rf .git/hooks/pre-push 删除这个 hook 即可

17 浏览
11 爬虫
0 评论