3

I have a django project that I've kept private for a long period of time. Through the lifespan of the project I've had settings.py, base_settings.py, and secret_settings.py files with sensitive information. Now I've decided to make the code open source as I am no longer actively working on the project.

I ran the commands below to remove the history of these files to make sure all sensitive information was gone.

git filter-branch -f --tree-filter 'rm -f exchange/secret_settings.py' HEAD
git filter-branch -f --tree-filter 'rm -f exchange/base_settings.py' HEAD
git filter-branch -f --tree-filter 'rm -f exchange/settings.py' HEAD

However, github warned me that there was still commits that had .py~ files with AWS information in them so I ran:

git filter-branch -f --tree-filter 'rm -f exchange/settings.py~' HEAD

I have secured my AWS account and removed all the secret keys from AWS so my account is secure. However, now I have duplicated commits, sometimes 3 or 4, for my entire commit history.

I've found various answers saying I can revert back to some .git/refs backups but that doesn't seem to be working.

Here is the project: https://github.com/ProgrammingJoe/Texchange

Does anyone know what I can do to fix this?

Programmingjoe
  • 2,169
  • 2
  • 26
  • 46

1 Answers1

3

I ended up doing some more googling after jhill's comment and I ran the following commands on a new branch:

git filter-branch -f --tree-filter 'rm -f exchange/settings.py' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/settings.py~' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/base_settings.py' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/base_settings.py~' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/secret_settings.py' HEAD       
git filter-branch -f --tree-filter 'rm -f exchange/secret_settings.py~' HEAD       

After that, my new branch was back where I wanted it with around 300 commits. I then had to figure out how to completely overwrite master with this other branch. In good practice, I cloned my repo in another location as a backup. I then tried every combination of force pushing and merging I could to overwrite the master branch and nothing worked. I then asked this question: Github, my branch is behind master but it is correct. How do I overwrite master with the branch?

I then realized that some of my older commits in master were where I wanted them so I ran:

git checkout master
git reset --hard correct_commit_id
git push -f origin master

This fixed all my issues but I accidentally deleted one of the files I used to have. Good thing I had a backup :). I'm not sure why git reset --hard fixed_branch didn't work in the past.

Programmingjoe
  • 2,169
  • 2
  • 26
  • 46