在所有git仓库提交中重命名短语(在子模块中)

时间:2018-11-12 20:41:24

标签: git bfg-repo-cleaner

如何为git子模块中的所有先前提交重命名短语?

phrase1 to phrase2

我的短语在.pack文件中找到。 (我缩短了十六进制的.pack名称):

$ 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

我尝试在仓库上运行BFG,但得到以下输出:

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

然后我尝试使用“ --no-blob-protection”参数运行BFG,但输出相同:

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

我的expression_file.txt具有以下格式:

phrase1 ==> phrase2

我研究过使用“ git filter branch”,但是我不确定要使用什么命令来重写这些文件。

1 个答案:

答案 0 :(得分:1)

只需回答问题的git filter-branch部分。 您可以使用以下方法在所有phrase1文件中用phrase2替换.txt

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

请注意,这可能会花费很多时间。 --all选项将在所有分支中执行替换。

相关问题