Sonia Singla

Git - Tracking method/function history

January 8, 2021 • ☕️ 1 min read

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

A quick example on this command:


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>

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

git log -L :<regex>:<file>

This was originally posted here! 💜

Relative Posts:

How to customize Oh My Zsh with Auto-Suggestions and Syntax Highlighting?

October 6, 2020

Hi 👋🏻, My name is Sonia, 20 yo, studying Information Technology from Panjab University, India. I am passionate about developer tooling and developer communities. Currently, working with Embark Studios on a new platform for gamemaking. I was the CNCF 2020 Intern at Thanos, and spent the winter of 2019 working with web-compatibility team of Mozilla as an Outreachy Intern. I also love to travel, teach, and speak about open source 👩🏻‍💻