Rewrite one line in one file in entire git history using git filter-repo

51 Views Asked by At

Just as the title says. Specifically, I want to change the value of a JSON file in the entire history of my git repo like

{
...
    "FOO": "yes"
...
}

to

{
...
    "FOO": "no"
...
}

I found similar answers using git filter-branch, but given that is a deprecated command, I want to know how to do this with git filter-repo.

1

There are 1 best solutions below

0
Antonio Petricca On

You could try with:

git filter-repo \
  --replace-content my-file.json \
  --code 'if match: return match.group(0).replace("\"FOO\":\"yes\"", "\"FOO\":\"no\"")'

I cannot try it because I have no repo such yours, but you could try it and give me a feedback.

Remember to install filter-repo extension as explained at https://github.com/newren/git-filter-repo/commit/74ea810872b41331ffdbf02cdc2d474c98b88514 .