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
- Host: GitHub
- URL: https://github.com/keith/diff-grep
- Owner: keith
- License: mit
- Created: 2020-10-28T03:25:22.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-12-17T20:00:25.000Z (over 3 years ago)
- Last Synced: 2025-01-09T03:22:56.092Z (over 1 year ago)
- Language: Rust
- Homepage:
- Size: 36.1 KB
- Stars: 28
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.
-no_uuid-
+
+ binaries without UUIDs may cause the debugger and crash reporting tools to
+ be unable to track and inspect the binary.
+
-random_uuid+
+ 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.
-root_safe-setuid_safe@@ -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 .
```