Skip to content

Git plugin for substituting a regular expression with some text across all files under revision control

License

Notifications You must be signed in to change notification settings

dspinellis/git-subst

Repository files navigation

Run Regression Test

git-subst

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.

Installation

Place the git-subst file in a directory of your PATH and give it execute permission.

Execution

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.

Examples

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

Author

Diomidis Spinellis

See also

git-grep(1), sed(1), Unix Tools: Data, Software and Production Engineering free massive open online course (MOOC) hosted by edX.

About

Git plugin for substituting a regular expression with some text across all files under revision control

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages