完全清除提交信息/重建版本库

创建一个新的 orphan 分支,代替原来的分支
git checkout --orphan <new-branch-name>
git add -A
git commit -am "Initial commit"
git branch -D <old-branch-name>
git branch -m <old-branch-name>
git push -f origin <old-branch-name>
直接删除 .git 然后重新初始化 git
rm -rf .git
git init
git add .
git cm "first commit"
git remote add origin [your_github_repo_url]
git push -f -u origin master

__pycache__ 文件夹误上传清理

__pycache__ 文件夹通常包含 Python 的字节码缓存文件。这些文件是 Python 解释器自动创建的,用于加速代码的执行。它们并不是源代码的一部分,也不需要(也不应该)被包含在源代码的版本控制中。

find . -name __pycache__ -type d -print | xargs rm -r
git rm -r --cached .
git add .
git commit -m "Remove __pycache__"
git push

这些命令首先会在你的项目目录中找到所有的 pycache 文件夹并删除它们,然后从 Git 的跟踪中移除所有文件,再重新添加所有文件(这时 pycache 文件夹已经被 .gitignore 忽略),最后提交和推送这些更改。

最后修改:2025 年 03 月 10 日
如果觉得我的文章对你有用,请随意赞赏