Get Into This

All the cool things.

Git Grep and Blame Bash Function

| Comments

Git has two very useful commands, git grep and git blame. The first one will find and print lines matching a certain pattern. The second one, given a file and line number, will tell you what revision and author last modified that line.

I was looking for a command that do both, but it seems that git is lacking such a command. Luckily, you can achieve this by using a simple bash function.

Simply add that function to your ~/.bashrc file (or where ever you keep your aliases and functions), and you will be able to do:

>ggb "Some string"

And this will grep your entire repository for “Some string” and print out the blame information for the file containing that pattern.

Comments