Search code examples
gitgithubgit-filter-repo

Git filter-repo not removing file from commit history


I realized today that a week or so ago (and about 10 commits ago), I accidentally committed a (mildly) private file to git that should not remain in my git commit history. I decided I would use git filter-repo to try to remove the file, but I'm having issues with it.

I started by running

git filter-repo --path credentials.ini  --invert-paths

but this didn't work because I didn't have a fresh clone of my repo. I then realized that I had never pushed my repository to my remote, so I simply copied my entire repository to my local machine to keep as a backup in case filter-repo didn't work. I then ran

git filter-repo --path credentials.ini  --invert-paths --force

after which the terminal outputted

Parsed 24 commits
New history written in 0.06 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at a72b0d4 Submit now doesn't work if there are any notes (i.e. errors). Bug still exists with submitting without refocusing first
Enumerating objects: 167, done.
Counting objects: 100% (167/167), done.
Delta compression using up to 8 threads
Compressing objects: 100% (143/143), done.
Writing objects: 100% (167/167), done.
Total 167 (delta 49), reused 41 (delta 11), pack-reused 0
Completely finished after 0.23 seconds.

I then used git log --stat to check if the file was still there, and it was. Git also had reset my HEAD back by at least one commit (maybe it was to the most recent commit, I'm not sure), and I was a little concerned about losing my commit history at this point so I just pushed everything to my remote at https://github.com/benvessely/brevets (commit starts with 6d31a and the file is credentials.ini, in case that helps). I checked on github and the credentials.ini file seemed to be there too, so it wasn't just that the file was showing up on my working tree but hadn't actually been deleted from the commit history or something. I then ran git filter-repo --path credentials.ini --invert-paths --force again just in case, but nothing changed.

This question had similar issues to me, but it seems like theirs just worked out without them really figuring out what was wrong.

Thanks for any help you can give!


Solution

  • The problem is that the path of your file is not credentials.ini. It is brevets/credentials.ini.