LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-sed

Find and replace across tracked files

TLDR

Find and replace in tracked files
$ git sed "[old]" "[new]"
copy
Replace with sed flags (e.g. case-insensitive)
$ git sed -f [i] "[old]" "[new]"
copy
Limit to a path
$ git sed "[old]" "[new]" -- [path/]
copy
Replace and commit the result
$ git sed -c "[old]" "[new]"
copy

SYNOPSIS

git sed [-c] [-f flags] search replacement [flags] [-- pathspec]

DESCRIPTION

git sed runs `git grep` to find matching files, then pipes them through `sed -i` to replace `search` with `replacement`, limiting changes to files tracked by Git so untracked or ignored files are never touched. Part of git-extras, it saves the separate `grep | xargs sed` pipeline for repository-wide renames.

PARAMETERS

SEARCH

Pattern to find.
REPLACEMENT
Text to substitute in.
-f, --flags flags
sed substitution flags to append (e.g. `g`, `i`); may also be given as a trailing positional argument.
-c, --commit
Commit the change afterward; fails if the working tree isn't already clean.
-- pathspec
Limit the replacement to matching files/paths.

INSTALL

sudo apt install git
copy
sudo dnf install git
copy
sudo pacman -S git
copy
sudo apk add git
copy
sudo zypper install git
copy
brew install git
copy
nix profile install nixpkgs#git
copy

SEE ALSO

sed(1), git-grep(1), git-extras(1)

RESOURCES

Copied to clipboard
Kai