我如何删除我存储在Git仓库中的所有文件和文件夹,但保留仓库?是否有某个命令可以重新启动Git仓库? 我找到了许多示例,但我搞得更糟了。该仓库已连接。如果有人愿意逐步向我解释,我将非常感激。
我如何删除我存储在Git仓库中的所有文件和文件夹,但保留仓库?是否有某个命令可以重新启动Git仓库? 我找到了许多示例,但我搞得更糟了。该仓库已连接。如果有人愿意逐步向我解释,我将非常感激。
如果你只有一个本地的git仓库
如果你想要清除整个历史记录并重新开始:
cd <repo>
rm -rf .git
git init
并重新开始提交。
如果您想删除文件和历史记录:
cd <repo>
rm -rf *
git init
并开始添加文件并提交...
如果您已连接到远程存储库 如果您想重新开始,但并不介意保留一些旧历史记录,则有一种快速的方法:
git pull
git rm -r *
git commit
git push
现在你的代码库又变为空了,只剩下一些旧历史记录。如果你也想清除所有历史记录,那就需要更多的工作(请注意,这将对与同一远程代码库链接的其他人造成麻烦):
git checkout <first commit hash>
git rm -r *
touch README
git add README
git commit --amend
git push -f
请注意,我为第一次提交创建了一个空的README文件,因为提交不能为空。
git push origin --delete <branchName>
(see "Delete a Git branch both locally and remotely")make a new orphan master branch (see "How can I completely empty the master branch in Git?")
git branch -D master
git checkout --orphan master
make at least one commit and push it.
git init
即可开始使用:对于本地代码库,您的问题没有意义。 - VonC重置提交或索引或工作树
git reset --hard <commit> # 重置提交、索引和工作树
删除引用日志
git reflog expire --expire=all --all # 清除引用日志
清理不必要的文件并优化本地仓库
git gc --prune=now
git push -f
完全覆盖当前存储库历史记录即可,这似乎毫无用处。 - ThanksForAllTheFish