Remove sensitive files and their commits from Git history

前端 未结 11 2186
借酒劲吻你
借酒劲吻你 2020-11-21 04:36

I would like to put a Git project on GitHub but it contains certain files with sensitive data (usernames and passwords, like /config/deploy.rb for capistrano).

I kno

11条回答
  •  遥遥无期
    2020-11-21 05:22

    To be clear: The accepted answer is correct. Try it first. However, it may be unnecessarily complex for some use cases, particularly if you encounter obnoxious errors such as 'fatal: bad revision --prune-empty', or really don't care about the history of your repo.

    An alternative would be:

    1. cd to project's base branch
    2. Remove the sensitive code / file
    3. rm -rf .git/ # Remove all git info from your code
    4. Go to github and delete your repository
    5. Follow this guide to push your code to a new repository as you normally would - https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

    This will of course remove all commit history branches, and issues from both your github repo, and your local git repo. If this is unacceptable you will have to use an alternate approach.

    Call this the nuclear option.

提交回复
热议问题