All Projects → da-x → git-search-replace

da-x / git-search-replace

Licence: other
A utility on top of Git for project-wide search-and-replace that includes filenames too

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to git-search-replace

CVparser
CVparser is software for parsing or extracting data out of CV/resumes.
Stars: ✭ 28 (-33.33%)
Mutual labels:  regex
cryptaddress.now
A minimal service to detect which cryptocurrency an address corresponds to.
Stars: ✭ 23 (-45.24%)
Mutual labels:  regex
ocaml-re-nfa
OCaml code to construct an NFA from a regular expression
Stars: ✭ 44 (+4.76%)
Mutual labels:  regex
dregex
Dregex is a JVM library that implements a regular expression engine using deterministic finite automata (DFA). It supports some Perl-style features and yet retains linear matching time, and also offers set operations.
Stars: ✭ 37 (-11.9%)
Mutual labels:  regex
pysorter
A command line utility for organizing files and directories according to regex patterns.
Stars: ✭ 40 (-4.76%)
Mutual labels:  regex
stat133-spring-2019
Course materials for Stat 133, Spring 2019, at UC Berkeley
Stars: ✭ 26 (-38.1%)
Mutual labels:  regex
eliza-rs
A rust implementation of ELIZA - a natural language processing program developed by Joseph Weizenbaum in 1966.
Stars: ✭ 48 (+14.29%)
Mutual labels:  regex
clausejs
Write contract once. Get data & function validators & conformers, an accurate & readable project contract, auto-generated API documentation, generative test coverage, plus more. A tool that enables a more predictable workflow for developing your JavaScript projects.
Stars: ✭ 29 (-30.95%)
Mutual labels:  regex
is-regex
Is this value a JS regex?
Stars: ✭ 22 (-47.62%)
Mutual labels:  regex
loadkit
Java 资源加载器,充分拓展ClassLoader#getResources(name)的能力,实现递归加载,支持普通风格 / 包名风格 / ANT风格 / 正则风格路径的资源加载同时支持自定义过滤器,通常作为框架的基础类库。
Stars: ✭ 39 (-7.14%)
Mutual labels:  regex
sortboard
A small ES6 library for easy sorting and filtering of elements.
Stars: ✭ 29 (-30.95%)
Mutual labels:  regex
RideShare-Trip-Stats
Chrome Extension to visualize your uber trip statistics
Stars: ✭ 61 (+45.24%)
Mutual labels:  regex
django-redirects
↪️ ✅ redirects as they should be, with full control.
Stars: ✭ 32 (-23.81%)
Mutual labels:  regex
fu
Unix's Find, Unleashed.
Stars: ✭ 32 (-23.81%)
Mutual labels:  regex
logwatch
日志采集工具
Stars: ✭ 22 (-47.62%)
Mutual labels:  regex
dora
Find exposed API keys based on RegEx and get exploitation methods for some of keys that are found
Stars: ✭ 229 (+445.24%)
Mutual labels:  regex
python-hyperscan
A CPython extension for the Hyperscan regular expression matching library.
Stars: ✭ 112 (+166.67%)
Mutual labels:  regex
Socially
Socially is a textView which is able to create separate clickable views according to your requirements.
Stars: ✭ 28 (-33.33%)
Mutual labels:  regex
java-core
Collections of solutions for micro-tasks created while building modules as part of project. Also has very fun stuffs :)
Stars: ✭ 35 (-16.67%)
Mutual labels:  regex
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (-38.1%)
Mutual labels:  regex

About

git-search-replace is a small utility on top of plain git for performing project-wide search-and-replace only on git-controlled files. It applies its searches to filenames as well as their content. The underlying syntax for the search regex is Python's.

It is designed to be a bit more instructive to the developer, compared to hackish bash scripts around sed.

An accompanying utility is gsr-branch, which does the same thing as git-search-replace but on the history of a branch (using git filter-branch). It's especially useful for fixing a whole bunch of commits at once when the fix is a simple search & replace (retaining a clean history).

Key features are:

  • By default, only act as grep to show what is going to change.
  • Dry run mode (--diff) shows a unidiff of the changes that the search-and-replace would do, so that the developer can review for correctness. No working directory files are modified.
  • Fix mode (--fix) performs the actual changes and associated 'git mv'.

Wait, but my awesome editor can already do that!

That's right, but when you are working within a group of people and everyone has their own editor, it becomes quite useful to be able to communicate renames in a way that everyone can easily reproduce, and during conflict resolution it is even more useful (see: git-mediate). This comes handy especially in commit message, for instance:

    commit 3ed68e243e76783fa2b92fa33f7e4681f0246332
    Author: Dan Aloni <[email protected]>
    Date:   Sun Jul 26 18:42:52 2015 +0300

    module: renamed with: gsr foo///bar -f

Syntax

Usage: gsr [options] (FROM-SEPARATOR-TO...)
       gsr [options] -p FROM1 TO1  FROM2 TO2 ...

Options:
  -h, --help            show this help message and exit
  -s STRING, --separator=STRING
                        The separator string the separates FROM and TO
                        regexes. /// by default, if -p is not specified
  -p, --pair-arguments  Use argument pairs for FROM and TO regexes. Useful with
                        shell expansion. E.g: colo{,u}r
  -f, --fix             Perform changes in-place
  -d, --diff            Use 'diff' util to show differences
  -e PATTERN, --exclude=PATTERN
                        Exclude files matching the provided globbing pattern
                        (can be specified more than once)
  -i PATTERN, --include=PATTERN
                        Include files matching the provided globbing pattern
                        (can be specified more than once)
  --no-renames          Don't perform renames

The expressions are tuples in the form of FROM-SEPARATOR-TO, with SEPARATOR defaults to '///'.

The -e and -i options abide by the following rules:

  • Each of these can be passed multiple times.
  • The order matters, as they are checked in that order for each file. Last matcher takes effect when matched.
  • If neither is passed, all files are included by default.
  • If -i if given first, then by default all files are excluded.

Examples

Shell escaping needs to be taken into consideration. The examples below should work with the major UNIX shells.

gsr old_name///new_name --diff

This shows a diff that represents the replacement of 'old_name' with 'new_name'.

gsr \\bold_name\\b///new_name --fix

This uses Python regex expression \b for matching at word boundaries for whole identifiers. This invocation will perform changes in-place because of '--fix'.

gsr 'things with space///with other stuff' --diff

Note that shells properly de-escape the quotes from the expression above.

Example of using gsr-branch:

gsr-branch.py HEAD~10 '(\.|\-\>)ol_header///\1header'

Runs the search replace regex over the last 10 commits, modifying them in-place. The regex will replace the string .ol_header (or ->ol_header) with .header (or ->header).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].