The git-subst Git subcommand substitutes the specified regular expression with the specified replacement. The substitution is only performed in the Git-tracked files that contain the specified RE located in the current directory and below.
Place the git-subst
file in a directory of your PATH and give it
execute permission.
Run the command as follows.
git subst
[-c
|-C
context-RE] [-n
] existing-RE-pattern replacement-string [pathspec...]
The command-line options have the following meanings.
-c
context
: Perform the change only on lines matching context regular expression.
-C
context
: Perform the change only on lines not matching context regular expression.
-n
: Only show what replacements will be performed.
pathspec... : If given, limit the search to paths matching at least one pattern. Both leading paths match and glob(7) patterns are supported.
git subst old new # Change old to new
git subst -c ^// old new # Change old to new only on lines starting with //
git subst -C ^// old new # As above only on lines not starting with //
git subst old new '*.js' # Change old to new only in .js files
git subst '\.Body' .body # . RE character is escaped
git subst '\<statuscode\>' statusCode # Matches whole words only
git subst '\.method\(\)' '.field' # .method() becomes .field
git subst '\.custom\(([^)]*)\)' '.\1' # .custom(foo) becomes .foo
Diomidis Spinellis
git-grep(1), sed(1), Unix Tools: Data, Software and Production Engineering free massive open online course (MOOC) hosted by edX.