Git grep/搜索特定分支 [英] Git grep/search a specific branch

查看:136
本文介绍了Git grep/搜索特定分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找grep某个分支的方法.简单吗?

I am looking for a way to grep a certain branch. Simple?

要在分支中显示特定文件,可以使用:

To show a specific file in a branch, one would use:

git show branch:my_branch bla_sheep.txt

类似的语法用于diff等.

Similar syntax is used to diff, etc.

有没有一种方法可以简单地grep分支:

Is there a way to simply grep a branch:

git grep branch:my_branch <regex>

推荐答案

要查看多个提交,从某些分支提示开始并向后工作: git grep可以查看任何特定的(因此,任何特定的提交都可以,因为任何给定的提交都标识了特定的树),但是要遍历某个分支中包含的每个提交,您将需要执行自己的git rev-list:

To look at multiple commits, starting at some branch tip and working backwards: git grep can look in any particular tree (hence any particular commit since any given commit identifies a particular tree), but to iterate over every commit contained within some branch, you will need to do your own git rev-list:

git rev-list branch | while read rev; do git grep <regexp> $rev; done

例如,

(但是您可能想更多地欣赏它,以便一旦找到所需内容,grep就会停止).

for instance (but you may want to fancy this up more so that your grep stops once you've found what you are looking for).

如果要查看一次,请在分支<branch>尖端的提交处查找并找到(或无法找到)<regexp>的任何实例,只需执行以下简单操作:

If you want to look once, at the commit that is the tip of branch <branch>, and find (or fail to find) any instances of <regexp>, just do a simple:

git grep <regexp> branch

循环表单仅适用于您希望从尖端开始提交并通过分支上的先前提交保持向后工作的情况.

The loop form is only for the case where you want to start at that tip commit and keep working backwards through previous commits on the branch as well.

这篇关于Git grep/搜索特定分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆