2

Based on this, I've tried to run git-filter-repo on a git local repo to replace some plain data in a single docker-compose.yml file using this expressions.txt file:

literal:DB_NAME=my_secret_database==>DB_NAME=${DB_NAME}
literal:DB_PASSWORT=my-secret-password==>DB_PASSWORT=${DB_PASSWORT}

and running it as:

$ git-filter-repo --path-glob 'docker-compose.yml' --replace-text expressions.txt --force

*disclaimer on the usage of --force: https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html#FRESHCLONE

The resulting message seems fine:

Parsed 212 commits
New history written in 0.39 seconds; now repacking/cleaning...
Repacking your repo and cleaning out old unneeded objects
HEAD is now at f7544c8 Refactor docker-compose file # <-- this was definitely NOT my HEAD prior to that
Enumerating objects: 33, done.
Counting objects: 100% (33/33), done.
Delta compression using up to 4 threads
Compressing objects: 100% (20/20), done.
Writing objects: 100% (33/33), done.
Total 33 (delta 12), reused 33 (delta 12), pack-reused 0
Completely finished after 0.49 seconds.

But then, many (many!) files simply disappeared from my repo, such as (non-exhaustive):

init.sh
.gitignore
.dockerignore
requirements.txt
Dockerfile
Dockerfile.dev
...

And I only got 11 commits left (/212 initially), strangely only those including modifications on the docker-compose.yml file, and I only have two branches left, again, only the ones including the docker-compose.yml file, all others are gone. I feel like I'm living in a wrong mirror world...

What did I do wrong/missed?

If that helps:

$ git-filter-repo --version
10401e45d5f0

$ git --version
git version 2.30.0
swiss_knight
  • 5,787
  • 8
  • 50
  • 92
  • 3
    If I'm not mistaken `--path-glob` (and friends) selects which files to keep in history, so you basically asked it to only keep `docker-compose.yml` and nothing else. I suggest you read the section about Path based filtering in the documentation. Were you trying to limit the text replacement to those files? – Hasturkun Jan 28 '21 at 12:27
  • Hmm, as the title of the linked question suggested (I found it on the top google links), yes, I am actually searching for a way to replace some expression by some other in this single file only (avoiding to search in all other files because I know they are healthy). But I naturally want to keep the rest as is. And to keep this file, after the replacement of course. – swiss_knight Jan 28 '21 at 12:30
  • I don't think that's an actual option at present, because content filtering is done over blobs, and blobs don't have names (an entry in a tree has a name and points to a blob, but multiple files might share a blob). You might want to request that as a feature (though I don't know how practical it is to implement). – Hasturkun Jan 28 '21 at 12:43
  • Actually, it might be possible using `git filter-repo`'s contrib script `bfg-ish`, which duplicates BFG's filtering behavior (`-fi` flag). I haven't actually tried it out myself, though. – Hasturkun Jan 28 '21 at 12:52
  • 1
    By simply removing the `--path-glob` option with its parameter, it seems to have done the job correctly as I only have the expression in that file, of course. – swiss_knight Jan 28 '21 at 13:01
  • related: https://github.com/newren/git-filter-repo/issues/74 – Ciro Santilli OurBigBook.com Jun 12 '23 at 09:12

0 Answers0