newren / git-filter-repo

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

Why "--invert-paths" when rewriting the history #486

Closed zhangk1551 closed 1 year ago

zhangk1551 commented 1 year ago

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository#using-git-filter-repo image

Base on the official document, "--invert-paths" and "--path" are used together to modify the entire history of the entire repo. I am curious that why not simply use "--path" without "--invert-paths"? What are the advantages to change the entire history instead of only the history that was affected?

newren commented 1 year ago

Base on the official document, "--invert-paths" and "--path" are used together

No, the official documentation has more examples of using --path without --invert-paths than using it with --invert-paths. In fact, the first example of using --path is without using --invert-paths.

to modify the entire history of the entire repo...What are the advantages to change the entire history instead of only the history that was affected?

Neither of these flags affect how much of the repo is considered. If you provide both flags, all history will be rewritten. If you only provide --path, all history will be rewritten. I'm not sure what led you to believe otherwise.

I am curious that why not simply use "--path" without "--invert-paths"?

You could take a look at the examples in the manual and their description to see why folks do that, but let me take a moment perhaps to provide some history...

Some users are only interested in removing a few files or directories, while others are only interested in keeping a few files or directories. Previous tools (git-filter-branch and bfg-repo-cleaner) focused solely on the removal of individually named files/directories, and often made it very difficult (if not impossible) to keep only individually named files/directories. That was a horrible design bug with those tools, in my opinion. I thought removing all files/directories except for certain ones was the more important usecase, so I made it the default with --path. I do fully understand that many users want the opposite, though, i.e. to just delete a few paths, so I added an --invert-paths flag for them.