newren / git-filter-repo

Quickly rewrite git repository history (filter-branch replacement)
Other
8.55k stars 708 forks source link

I tried --invert-paths it didn't seem to do anything [another mistaken --paths vs --path issue] #532

Closed geoidesic closed 4 months ago

geoidesic commented 11 months ago
hostname % ls web/index.html
web/index.html
hostname % git-filter-repo --paths web/index.html --invert-paths
Parsed 74 commits
New history written in 38.96 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at eada142 Merge branch 'SPORTCH-138-new-side-menu'
Enumerating objects: 11303, done.
Counting objects: 100% (11303/11303), done.
Delta compression using up to 8 threads
Compressing objects: 100% (9046/9046), done.
Writing objects: 100% (11303/11303), done.
Total 11303 (delta 1970), reused 11303 (delta 1970), pack-reused 0
Completely finished after 39.55 seconds.
hostname % ls web/index.html
web/index.html
hostname % git status
On branch main
nothing to commit, working tree clean
hostname %

The scenario is someone committed a file they should have. Now it's in .gitignore but git insists on still tracking it (probably because it's already part of the repo). I've tried everything to get git to stop tracking that damn file and I've failed. This was my last resort and it failed too.

newren commented 5 months ago

The problem here, sadly, is that you used --paths rather than --path. Python has this "helpful" feature where if you don't type the full argument, so long as you type enough leading characters that no other argument could also be spelled with those characters, then it completes it for you. For example, if you had a script that accepted both --dostuff and --runitall, then you wouldn't need to type myscript --dostuff, you could get away with myscript --do and it'd complete that to the longer form for you.

In this case, the option you wanted was --path, but there is also an option named --paths-from-file. Since --paths is only a prefix of --paths-from-file, it picks that option. And that means git-filter-repo treats web/index.html as a file that is supposed to contain a list of filenames you want to keep, one per line (or, since you are using --invert-paths, a list of filenames you want to expunge). Since web/index.html probably have any lines that name any files in your repository, git-filter-repo doesn't find anything to remove.

If you use --path instead of --paths, then that'll fix this.

Sorry for taking so long to respond... :-(

newren commented 4 months ago

Pushed fd5ce386a689 (filter-repo: make --paths as an option throw an error, 2024-07-02) to prevent others from making the same mistake in the future.