【Git】如何清除 Git 仓库的所有提交记录

    技术2022-07-10  134

    在做项目提交是,不小心将敏感信息提交到代码仓库,并且已发布到公共仓库中,后续操作虽然将敏感信息进行替换后,提交的历史记录中依然可以查询到敏感信息,如何将提交信息清除,成为困扰自己的问题。

    经过以下步骤后,你将获得一个清爽的仓库

    切换到新的分支 git checkout --orphan latest_branch 缓存所有文件(处理 .gitignore 中声明排除的) git add -A 提交跟踪过的文件(Commit the changes) git commit -am "commit message" 删除 master 分支(Delete the master branch) git branch -D master 重命名当前分支为 master(Rename the current branch to master) git branch -m master 提交到远程 master 分支(Finally, force update your repository) git push -f origin master
    Processed: 0.013, SQL: 9