在所有分支的一个文件中搜索字符串

时间:2016-05-13 15:22:32

标签: git

是否可以在所有分支中的一个文件中使用 grep 字符串?

我知道我对特定文件进行了更改;我无法找到我做过的那个分支。

2 个答案:

答案 0 :(得分:1)

感谢ElpieKay提供这个漂亮的小宝石:

git grep a_string $(git rev-parse --all -- target_file)

答案 1 :(得分:0)

Use:

git stash
git branch | while read line
do
echo branch:$line
git checkout $line -- target_file
grep a_string target_file
done
git stash pop

Have a try.