Skip to content

Instantly share code, notes, and snippets.

@helhum
Created September 12, 2014 15:06
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save helhum/2b2078901f040622b403 to your computer and use it in GitHub Desktop.
Save helhum/2b2078901f040622b403 to your computer and use it in GitHub Desktop.
Git command to show (remote) branches and tags that contain a commit with a specified commit message
#!/bin/bash
function search-branches() {
for sha1 in `git log --oneline --all --grep "$1" | cut -d" " -f1`
do
git branch -r --contains $sha1
done
}
function search-tags() {
for sha1 in `git log --oneline --all --grep "$1" | cut -d" " -f1`
do
git tag --contains $sha1
done
}
echo -e "\nRemote branches with '$1' in commit message:"
search-branches $1;
echo -e "\nTags with '$1' in commit message:"
search-tags $1;
# Put this script in any place in your PATH then you can show branches and tags that contain certain commit messages
# $ git search-commit-message "Fixes #1234"
@jpruiz114
Copy link

Do you have to save this as a shell script with sh extension? I'm trying to call it but I'm getting some errors around the functions call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment