Reputation: 998
I have a Git repository of a rather large software project. I'd like to search every single commit message for a certain substring. I'm not looking for just the commits on the current branch, but every single commit that the repository is aware of.
The results do not have to be in any particular order (though if there was some order, it would be great). Is this possible? How can I go about doing this? I see that "git log -c -S " is useful, but that seems to work for on the current branch.
Upvotes: 7
Views: 1262
Reputation: 1112
To search the commit log (across all branches) for the given text:
git log --all --grep='Build 0051'
To search the actual content of commits through a repository's history, use:
git grep 'Build 0051' $(git rev-list --all)
to show all instances of the given text, the containing file name, and the commit SHA-1 has value.
Finally, as a last resort in case your commit is dangling and not connected to history at all, you can search the reflog itself with the -g
flag (short for --walk-reflogs
:
git log -g --grep='Build 0051'
If you seem to have lost your history, check the reflog
as your safety net. Look for Build 0051 in one of the commits listed by
git reflog
You may have simply set your HEAD
to a part of history in which the 'Build 0051' commit is not visible, or you may have actually blown it away. The git-ready reflog article may be of help.
To recover your commit from the reflog: do a Git checkout of the commit you found (and optionally make a new branch or tag of it for reference)
git checkout 77b1f718d19e5cf46e2fab8405a9a0859c9c2889
# alternative, using reflog (see git-ready link provided)
# git checkout HEAD@{10}
git checkout -b build_0051 # make a new branch with the build_0051 as the tip.
Upvotes: 11
Reputation: 888
You can use git log -g --grep=search_for_this
. Also, there are some GUI clients for tracking your repository. Search through the commits in all branches would be possible. If you want to try a GUI, you can check the awesome-git repository out.
I tried with --all
flag, It worked as well. You can also use
git log --all --grep=search_for_this
Upvotes: 1
Reputation: 1071
The --all flag considers every branch your local repository is aware of:
git log --all --grep="substring"
Upvotes: 2