Renaming phrase in all git repository commits (in submodules)

110 views Asked by At

How can I rename a phrase for all previous commits in my git submodules?

phrase1 to phrase2

My phrase is found in .pack files. (I shortened the hex .pack names):

$ grep -rnw . -e 'phrase1'
Binary file ./.git/modules/folder1/objects/pack/pack-6170d.pack matches
Binary file ./.git/modules/folder2/modules/objects/pack/pack-934ef.pack matches
Binary file ./.git/modules/folder2/objects/1b/2eeaa matches
Binary file ./.git/modules/folder2/objects/1e/92b8b matches
Binary file ./.git/objects/54/fcce26 matches

I tried running BFG on the repo but I get this output:

java -jar bfg-1.13.0.jar -rt expression_file.txt /my_repo/
...
BFG aborting: No refs to update - no dirty commits found??
...

And I tried running BFG with the "--no-blob-protection" argument but I get the same output:

...
BFG aborting: No refs to update - no dirty commits found??
...

My expression_file.txt has this format:

phrase1 ==> phrase2

I looked into using "git filter branch" but I am not sure what command to give it to make it rewrite these files.

1

There are 1 answers

0
Romain Warnan On BEST ANSWER

Just to answer to the git filter-branch part of the question. Here is how you can use it to replace phrase1 with phrase2 in all .txt files :

git filter-branch -f --tree-filter '
    find . -type f -name '*.txt' -exec sed -i 's/phrase1/phrase2/g' {} +
' --prune-empty --all

Be aware that it can be very time conumming. The --all option will perform the replacement in all branches.