Skip to content

Instantly share code, notes, and snippets.

@snail007
Created April 9, 2019 06:11
Show Gist options
  • Save snail007/83e93e62a3abc390a649b2d96c1a61c4 to your computer and use it in GitHub Desktop.
Save snail007/83e93e62a3abc390a649b2d96c1a61c4 to your computer and use it in GitHub Desktop.
git仓库删除所有提交历史记录,成为一个干净的新仓库,把旧项目提交到Git上,但是会有一些历史记录,这些历史记录中可能会有项目密码等敏感信息。如何删除这些历史记录,形成一个全新的仓库,并且保持代码不变呢?
1.Checkout
git checkout --orphan latest_branch
2. Add all the files
git add -A
3. Commit the changes
git commit -am "commit message"
4. Delete the branch
git branch -D master
5.Rename the current branch to master
git branch -m master
6.Finally, force update your repository
git push -f origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment