I want to search across all possible refs (commits/branches/tags), all commit messages, all branch names, and all commit contents.
Asked
Active
Viewed 702 times
1
-
A useful preliminary step is first clone all remote branches: https://stackoverflow.com/a/68582362/565877 – Devin Rhode Feb 20 '22 at 23:12
-
2Not in one command, but with an alias to chain commands, yes. But I guess this would be out of your question scope? – Romain Valeri Feb 21 '22 at 03:04
-
1I don't really mind what the implementation is, just want to easily search everything stored in git. In fact, I fully expect this is necessary, given the request to search _ev_er_ry_thing_ – Devin Rhode Feb 21 '22 at 15:02
-
How does what you want differ from searching through `git log -p --all`? – jthill Jun 02 '22 at 17:45
-
`git log -p --all` is a totally valid strategy for doing this search! See below answer :) – Devin Rhode Jun 02 '22 at 21:14
2 Answers
3
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

Romain Valeri
- 19,645
- 3
- 36
- 61
-1
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.
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:

Devin Rhode
- 23,026
- 8
- 58
- 72

Fuad Zein
- 230
- 1
- 9
-
1You have not understood the question. Neither original nor useful in this context. – matt Feb 21 '22 at 02:32
-
I just realized this is not completely off-base, but missing some CRUCIAL points tying it back to original question. I've edited this answer to connect back to the original request in my question. – Devin Rhode Feb 24 '22 at 17:05
-
It would be really nifty to pipe this output into some sort of search tool, but my command line skills are not there yet – Devin Rhode Feb 24 '22 at 17:06