How to delete something that was accidentally pushed

≯℡__Kan透↙ 提交于 2019-12-12 12:22:10

问题


I wanted to do source control on my website. There were a lot of files so I just went git add -a

Unfortunately, I accidentally committed and pushed a file called credentials.txt that had my ftp and db details. I've tried deleting the file, committing then pushing but it still shows the file when I browse my repo on github in the history.

Is there anyway to get rid of this?


回答1:


Github has a nice guide on this exact topic. It explains how to get it out of the repository, as well as how to deal with the data that may already be in public hands.




回答2:


You'll have to rewrite history using git filter-branch. Andy has posted a link to a guide on github for doing this.

Regardless of that, removing the file won't undo the damage - anyone who pulled your repo in the meantime has it, and at the very least it's in github's infrastructure. So, don't bother.

Instead of trying to hide what happened, do damage control and change your passwords. Don't try to contain a secret that's already out - to quote Benjamin Franklin, "the only way three people can keep a secret is if two of them are dead".

If it's on the Internet even for a moment, it's safe to assume it's been saved by a dozen or more people. If you don't work from that perspective it will probably come back to bite you.



来源:https://stackoverflow.com/questions/9243596/how-to-delete-something-that-was-accidentally-pushed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!