不少人有一個大膽的想法,如何清空某個分支裏面全部的 commit 呢?還有一個場景,不熟悉 Git 的程序員門新建分支基於某個分支建立的,可是可能這個分支的歷史 Commits 是不須要的。那麼,下面我就說一下如何將分支的歷史 Commits 清空吧!git
首先,你應該切換到你須要清空的分支,而後執行 (咱們擬定爲 test
吧):程序員
git checkout --orphan null_branch
而後你會發現,你分支下的全部文件都成了待添加狀態,咱們能夠直接執行 git add -A
添加,而後先存在 null_branch
中 git commit -am "Init commit."
shell
git branch -D test
刪除是爲了將
null_branch
重命名爲以前的分支名稱
而後執行重命名爲以前的分支名稱:this
git branch -m test
git push -f origin test
若是你使用過 GitHub 或者 SourceTree 可能會遇到:code
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 便可。rem