Is there a way to show the git-diff filtered by a given pattern.
Something like
git grepdiff pattern changed file +++ some sentence with pattern changed file 2 --- some other pattern
Unfortunately the simplest solution is not good enough
git diff | grep pattern +++ some sentence with pattern --- some other pattern # not an option as doesn't put the filename close to the match
I came with a workaround using awk
git diff | awk "/\+\+\+/{f = \$2}; /PATTERN/ {print f \$0} "
But would love to find out that there is a command for this.
The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .
The git diff command allows us to compare different versions of branches and repository. To get the difference between branches, run the git diff command as follows: $ git diff <branch 1> < branch 2>
`git grep` command is used to search in the checkout branch and local files. But if the user is searching the content in one branch, but the content is stored in another branch of the repository, then he/she will not get the searching output.
Not sure but isn't git diff -G <regex>
flag OK?
-G < regex>
Look for differences whose added or removed line matches the given <regex>.
Have you tried git diff -S<string>
or git diff -G".*string.*"
? Note that they are not equivalent, see the documentation about pickaxe for what -S does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With