DEV Community ðŸ‘Đ‍ðŸ’ŧðŸ‘Ļ‍ðŸ’ŧ

DEV Community ðŸ‘Đ‍ðŸ’ŧðŸ‘Ļ‍ðŸ’ŧ is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Sonia Singla
Sonia Singla

Posted on • Originally published at soniasingla.com

Git - Tracking method/function history

The git log command helps us to view the information about previous commits occurred in the project. But do you know, you can see the history of any method/function in your codebase easily with:

git log -L :function:path/to/file
Enter fullscreen mode Exit fullscreen mode

A quick example on this command:

Alt Text

It cannot necessarily handle all the languages, for that, you need to configure the git config correctly in order for git to recognize method/function declarations in that specific language.

I checked for Golang, JavaScript, Python and C, it's working without adding any particular language-specific configuration.

Interestingly, if you wish to check the history for some specific number of lines within the file, you can check with:

$ git log -L :<start>,<end>:<file>
Enter fullscreen mode Exit fullscreen mode

You can also pass regex to find anything in your codebase files using:

git log -L :<regex>:<file>
Enter fullscreen mode Exit fullscreen mode

This was originally posted here! 💜

Top comments (0)

🌙 Dark Mode?!

Turn it on in Settings