Find a specific couple lines of code from a large git repository

So, I remember that I once did something in another project and (later deleted it), which may be useful now. Thanks to some other SO post, I was able to search the repository for a half-memorable string.

git grep halfRemeberedNameOfFunction $(git log -g --pretty=format:%h) 

and yay! got some results

 2d0bcde:path/to/project/file.c: result = halfRemeberedNameOfFunction( data ); 65fc672:path/to/project/file.c: result = halfRemeberedNameOfFunction( data ); 24f2858:path/to/project/file.c: result = halfRemeberedNameOfFunction( data ); 252e3a5:path/to/project/file.c: result = halfRemeberedNameOfFunction( data, args ); b58bc0b:path/to/project/file.c: result = _halfRemeberedNameOfFunction( data, options ); dce8d9d:path/to/project/file.c: result = halfRemeberedNameOfFunction( data, moreData ); 

But is this not enough for the surrounding code? How can I get the whole file in one of these fixes?

Many thanks

+4
source share
1 answer

You can transfer part of the file to git show:

 git show 252e3a5:path/to/project/file.c 
+6
source

Source: https://habr.com/ru/post/1307775/


All Articles