newren / git-filter-repo

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

FIlter problem #592

Closed rokn closed 2 months ago

rokn commented 3 months ago

Hey so i've ran this command:

git filter-repo --path channels.yaml --replace-text <(echo 's/the-secret-i-commited/[SECRET]/') --force

And now I'm left with only the 4 commits in which I've edited the channels.yaml file, and all other files are missing. I'm hoping there is some revert operation or backup saved somewhere as I haven't pushed the repo to a remote and I don't have a backup... please.

rokn commented 3 months ago

Okay I've managed to recover my files through the IDE(JetBrains Local history ftw). But yeah the above command seems like it shouldn't do what it did, seems a bit counterintuitive.

newren commented 3 months ago

Hey so i've ran this command:

git filter-repo --path channels.yaml --replace-text <(echo 's/the-secret-i-commited/[SECRET]/') --force

And now I'm left with only the 4 commits in which I've edited the channels.yaml file, and all other files are missing...the above command seems like it shouldn't do what it did, seems a bit counterintuitive.

I don't understand why you think it shouldn't have done exactly what it was documented to do. From the documentation for the --path option:

  --path-match DIR_OR_FILE, --path DIR_OR_FILE
                        Exact paths (files or directories) to include in
                        filtered history. Multiple --path options can be
                        specified to get a union of paths.

In other words, it's only going to include the specified paths (channels.yaml in your case) when you use this flag, while excluding all others. If you wanted it to exclude that path and keep all other paths, then you need:

  --invert-paths        Invert the selection of files from the specified
                        --path-{match,glob,regex} options below, i.e. only
                        select files matching none of those options.

I'm hoping there is some revert operation or backup saved somewhere as I haven't pushed the repo to a remote and I don't have a backup... please.

  --force, -f           Rewrite repository history even if the current repo
                        does not look like a fresh clone. History rewriting is
                        irreversible (and includes immediate pruning of
                        reflogs and old objects), so be cautious about using
                        this flag.

I'm glad you were able to recover your files through your IDE's copy. Please do read what options do before simply invoking them, so as to avoid scares like this. Anyway, glad you're in a good state now.