An open API service indexing awesome lists of open source software.

https://github.com/keith/diff-grep

Filter matching hunks in diffs
https://github.com/keith/diff-grep

Last synced: 10 months ago
JSON representation

Filter matching hunks in diffs

Awesome Lists containing this project

README

          

# diff-grep

`diff-grep` is a tool for filtering diffs to only include the hunks
matching the given patterns.

## Usage

Produce a diff, for example using `git diff`:

```diff
$ git diff ... > /tmp/original.diff
$ cat /tmp/original.diff
diff --git c/docs/ld.1.html w/docs/ld.1.html
index 2ac7626c..eeb7bdc5 100644
--- c/docs/ld.1.html
+++ w/docs/ld.1.html
@@ -897,7 +903,16 @@ When linking for two-level namespace, ld does not verify
build time. This option relaxes that requirement, allowing you to mix
object files compiled for different ARM subtypes.


-
Do not generate an LC_UUID load command in the output file.

+
Do not generate an LC_UUID load command in the output file. Be warned that
+ binaries without UUIDs may cause the debugger and crash reporting tools to
+ be unable to track and inspect the binary.

+

+
Generate a random LC_UUID load command in the output file. By default the
+ linker generates the UUID of the output file based on a hash of the output
+ file's content. But for very large output files, the hash can slow down
+ the link. Using a hash based UUID is important for reproducible builds,
+ but if you are just doing rapid debug builds, using -random_uuid may
+ improve turn around time.


Sets the MH_ROOT_SAFE bit in the mach header of the output file.


@@ -1315,7 +1330,7 @@ as(1), ar(1), cc(1), nm(1), otool(1) lipo(1), arch(3), dyld(3), Mach-O(5),



- March 7, 2018
+ August 7, 2020
Darwin


```

Filter the diff where every modified line in a hunk must match the given
pattern(s):

```diff
$ cat /tmp/original.diff | diff-grep foot-date --output /tmp/filtered.diff
$ cat /tmp/filtered.diff
--- c/docs/ld.1.html
+++ w/docs/ld.1.html
@@ -1315,7 +1330,7 @@ as(1), ar(1), cc(1), nm(1), otool(1) lipo(1), arch(3), dyld(3), Mach-O(5),



- March 7, 2018
+ August 7, 2020
Darwin


```

Use the filtered diff somewhere:

```sh
$ git apply --reverse /tmp/filtered.diff
```

In this example, we revert only the matching hunk using `git apply
--reverse`. This can be useful when you want to stage, or checkout,
large mechanical diffs that you have intertwined other changes with.

## Installation

[Homebrew](https://brew.sh):

```sh
brew install keith/formulae/diff-grep
```

Manually, after [installing rust](https://rustup.rs/):

```sh
cargo install --locked --path .
```