How to substitute text from files in git history?

I’d recommend using the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch specifically designed for rewriting files from Git history. You should carefully follow these steps here: https://rtyley.github.io/bfg-repo-cleaner/#usage – but the core bit is just this: download the BFG’s jar (requires Java 7 or above) and run this command: $ java -jar bfg.jar –replace-text replacements.txt … Read more

How can I use a variable in the replacement side of the Perl substitution operator?

On the replacement side, you must use $1, not \1. And you can only do what you want by making replace an evalable expression that gives the result you want and telling s/// to eval it with the /ee modifier like so: $find=”start (.*) end”; $replace=””foo $1 bar””; $var = “start middle end”; $var =~ … Read more

sed substitution with Bash variables

Variables inside ‘ don’t get substituted in Bash. To get string substitution (or interpolation, if you’re familiar with Perl) you would need to change it to use double quotes ” instead of the single quotes: # Enclose the entire expression in double quotes $ sed “s/draw($prev_number;n_)/draw($number;n_)/g” file.txt > tmp # Or, concatenate strings with only … Read more