Created
January 12, 2012 10:37
-
-
Save pete-otaqui/1599786 to your computer and use it in GitHub Desktop.
Find File Path Pattern in all git branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Authored by Pete Otaqui <[email protected]> | |
# | |
# Core code taken from StackOverflow | |
# http://stackoverflow.com/questions/372506/how-can-i-search-git-branches-for-a-file-or-directory | |
# | |
# The author has placed this work in the | |
# Public Domain, thereby relinquishing all | |
# copyrights. Everyone is free to use, modify, | |
# republish, sell or give away this work | |
# without prior consent from anybody. | |
usage() { | |
echo | |
echo $0 - Search for file paths in git branches | |
echo | |
echo Use this script to apply an extended regex | |
echo search to all file names in all local git | |
echo branches. Very helpful in finding files | |
echo that you created "somewhere" or that have | |
echo been moved | |
echo | |
echo Usage: | |
echo $0 path/to/lost_file.* | |
echo | |
} | |
[[ -n "$1" ]] || { usage; exit 0 ; } | |
for branch in `git for-each-ref --format="%(refname)" refs/heads`; | |
do | |
echo | |
echo $branch :; | |
git ls-tree -r --name-only $branch | grep -E "$1" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment