使用命令:(

git filter-branch
命令的作用:进行历史记录重写)(在根目录下运行)

git filter-branch --index-filter <span style="color:#abe338">&#39;git rm --cached --ignore-unmatch &lt;file_path&gt;&#39;</span> -- --all

然后使用:(

git push --force
命令将更改的历史记录强制推送到远程仓库)

git push --force origin

注意:

如果运行的时候不是在根目录或者文件的路径写的不对,提示了&lsquo;cannot create a new bachup&rsquo;就使用:

rm -r .git/refs/original/

如果是windows,使用:

rmdir /s .git\refs\original

删除后,继续使用:

git filter-branch --index-filter <span style="color:#abe338">&#39;git rm --cached --ignore-unmatch &lt;file_path&gt;&#39;</span> -- --all

然后继续操作。即可。