I'm following this answer to remove a single file containing credentials from git history. I have git 2.35.1 and filter-repo 22826b5a68b6. The command I need is apparently:
git-filter-repo --path auth.json --invert-paths
If I try to apply this to my working repo, I get this error:
Aborting: Refusing to destructively overwrite repo history since
this does not look like a fresh clone.
(expected freshly packed repo)
So I check out a fresh copy with git clone
, and the command runs successfully:
Parsed 861 commits
New history written in 0.69 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at 7212384 Update app.css
Enumerating objects: 8203, done.
Counting objects: 100% (8203/8203), done.
Delta compression using up to 24 threads
Compressing objects: 100% (2310/2310), done.
Writing objects: 100% (8203/8203), done.
Total 8203 (delta 5630), reused 8196 (delta 5623), pack-reused 0
Completely finished after 2.85 seconds.
And I can see that the file has been removed. But when I go to push:
git push --force
fatal: No configured push destination.
for some reason it's lost the remote it cloned from, so I add it back in manually:
git remote add origin [email protected]:abc/xyz.git
This fails with:
fatal: The current branch master has no upstream branch.
so I add that with
git push --set-upstream origin master
but this fails too:
To git.example.com:abc/xyz.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git.example.com:abc/xyz.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
but I know that nothing has been pushed to this repo since checking it out. Repeating the process has the same result. If I do a git pull
to update it, it then fails again with the this does not look like a fresh clone
error, right back where I started.
I went round and around this a few times, eventually getting past all the errors, only to find that it has all made no difference to my repo – the file is still there.
So my question is what are the exact steps I should do to make this filtering process work on a freshly cloned repo?
git push --force origin master
– Chitongit gc
in your initial repo to makegit filter-repo
happy – Chitongit filter-repo
, but it seems like not actually removing the File, but only the Committed History? \ I have to manually remove the file first, then use this to remove the committed history (-- so, yes, providing a path to a already removed file..). \ Have no idea I did it right or not. The history seems gone now. \ Though if I kept a link to the history before its removed, I can still access the file in a "removed history"?... – Pochard