Issue
I would like to use git grep from outside the repository, for example editing a file in vim. This works:
git -C /path/to/gitrepo/ grep 'my search'
The problem is that the results show relative path from /path/to/gitrepo
. So, I cannot open them directly.
Is there any way to generate the full file path to the matches? From git
would be great, but a hacky solution to prepend and build the absolute path will do too.
Solution
The usual output is just one line per match (though this does depend on options). In this case, a simple git -C $path grep pattern | sed s,^,$path,
does the trick (assuming no "," in paths).
– torek
Answered By - Armali Answer Checked By - Dawn Plyler (WPSolving Volunteer)