Devin Rhode
Devin Rhode

Reputation: 25377

Git: search all commit messages, branch names, commit contents, in one command

I want to search across all possible refs (commits/branches/tags), all commit messages, all branch names, and all commit contents.

Upvotes: 2

Views: 1185

Answers (2)

Fuad Zein
Fuad Zein

Reputation: 224

You can try printing everything to the terminal, and then searching output with your terminal application:

git log -5000 -p --all --decorate --oneline --graph

For performance reasons, this is limited to 5,000 commits.

sample output from command

There's a bit more noise/information than originally requested, but this can be beneficial - for example, you can now search commit hashes, timestamps, author names. You can intuitively search for deleted files, etc.

You could include --oneline if performance is an issue. It causes author and date information to be omitted:

diff of oneline

Upvotes: -1

Romain Valeri
Romain Valeri

Reputation: 22067

Since noone suggested a chain of commands yet, and in case you did not craft it yourself already :

git config alias.findall '!f() { echo -e "\nFound in refs:\n"; git for-each-ref refs/ | grep $1; echo -e "\nFound in commit messages:\n"; git log --all --oneline --grep="$1"; echo -e "\nFound in commit contents:\n"; git log --all --oneline -S "$1"; }; f'

It chains these three commands :

# for branches and tags we use for-each-ref and pipe the result to grep
git for-each-ref refs/ | grep $1

# for commit messages we use the grep option for log
git log --all --oneline --grep="$1"

# and for commit contents, the log command has the -S option
git log --all --oneline -S "$1"

So now you can just do

git findall something

Upvotes: 3

Related Questions