For my Swift project, I'm trying to identify changes in the project.pbxproj file that have a particular word or regex in the surrounding context lines (not within the actual diff changes).
I've tried to use
git diff -G"<searchterm>"
But this seems to only apply the regex to the changes in the diff, not the surrounding context lines.
Tried also:
git diff -U# -G"<searchterm>"
but this doesn't alter the searchable lines.
example:
targeted diff looks like:
repositoryURL = "[email protected]:myRepo.git"
requirement = {
- branch = main;
- kind = branch;
+ kind = upToNextMajorVersion;
+ minimumVersion = 1.0.0;
};
};
running git diff -G"kind" or git diff -G"branch" will return a success, but git diff -G"repositoryURL" does not.
I would use grep and not try to leverage gits search for this.
Something like
git diff | grep -A 5 myRepoIn your example would produce:
For context control in grep, from the man page:
https://www.man7.org/linux/man-pages/man1/grep.1.html