git log grep — Search a git repository for a particular commit message — Big Fat Software, Inc.

To search commit-message one-liners

git log --pretty=oneline --abbrev-commit --grep="TICKET-1234"
git log --grep="TICKET-1234"
git log --name-status --grep=""
git log --pretty=oneline --abbrev-commit --grep=""
git log --pretty=oneline --abbrev-commit --name-status --grep=""
git log --pretty=format:%s --grep=""

Simple Unix grep:

git log | grep -b3 "TICKET-1234"
git log --pretty=oneline | awk '{print $1}'

Creating an alias

[alias] find = log --pretty=\"format:%Cgreen%H %Cblue%s\" --name-status --grep
git find "string"
[alias] lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git lg --grep=""
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

To search and grep across all branches and and all commit messages for the given piece of text :

git log --all --grep='TICKET-1234'
git log --pretty=\"format:%Cgreen%H %Cblue%s\" --name-status --grep

To search the actual content of commits through a repository’s history:

git grep 'TICKET-1234' $(git rev-list --all)

To show all instances of the given text, the containing file name, and the commit SHA-1.

git grep 'TICKET-1234' $(git rev-list --all)
git log -g --grep='TICKET-1234'
git reflog
git checkout 77b1f718d19e5cf46e2fab8405a9a0859c9c2889
# alternative, using reflog (see git-ready link provided)
git checkout HEAD@{10}

# make a new branch with the build_0051 as the tip
git checkout -b build_0051



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store