在Github项目中搜索代码 [英] Search code inside a Github project

查看:426
本文介绍了在Github项目中搜索代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在grep里面找到Github项目代码中的东西?



我可以在本地拉取源代码并grep,但我想知道是否可以通过网页界面或第三方的替代品。



点子?

解决方案

< 2013年1月更新: ,或:


  • 从中选择代码存储库用户下拉菜单和

  • 使用为该搜索类型列出的相应前缀。



例如,使用 回购:username / repo-name 指令将搜索限制到代码存储库。

初始高级搜索页面包含部分:


代码 搜索:



代码搜索将查看通过GitHub公开托管的所有代码。您也可以按照以下方式进行过滤:




  • 语言 language:
  • 存储库名称(包括用户名) repo:

  • 文件路径 路径:


因此,如果您选择代码搜索选择器,那么对于回购中的文本的查询grepping将会起作用:








GitHub的 无用


  • 如果您忘记放置正确的搜索选择器(这里是 Code ),您将收到一条错误消息: >
    无效的搜索查询。尝试引用它。






  • 错误信息根本无法帮助您。

    不包含引用它的数量会让你摆脱这个错误。一旦你收到这个错误信息,你就不会得到这些部分,提醒你正确的关联搜索

  • em>选择器(存储库用户语言)和(右)搜索过滤器(这里 repo:)。
    您做的任何进一步尝试都不会显示那些关联(选择器过滤器)。只有上面显示的错误消息...

    要取回这些数组的唯一方法是单击高级搜索图标:







  • 所有内容搜索选择器,这是默认的,实际上是所有搜索过滤器的错误之一!除语言:... ...

    (您可以想象/假设所有东西 可以帮助你选择搜索过滤器实际工作的任何搜索选择器 repo:,但是不会,这太容易了)


  • 您无法单独通过高级搜索字段指定所需的搜索选择器!

    (但您可以用语言:,即使 Search Language 是另一个组合框,就在搜索'type'one ...)









因此,用户的体验通常如下:

  • 点击高级搜索,浏览过滤器的这些部分,并注意要使用的部分: repo:

  • 第一个高级搜索 repo:jruby / jruby stat ,但是用d默认搜索选择器一切


    => FAIL ! (以及显示Selectors-Filters关联的数组已不存在
  • 您注意到搜索选择器thingy,请选择 first 选择存储库(Dah!我想在存储库中搜索...)

    => FAIL

  • 沮丧,您选择下一个选择器(这里是 Users )甚至没有看到所述选择器,只是给它一个尝试... ...
    => FAIL

  • 拧这个,GitHub搜索破坏!我不在这里!

    ...

    (GitHub高级搜索是实际上没有损坏,只有他们的GUI是......)


    $ b

    因此,回顾一下,如果您想在Github项目代码中寻找某些东西,那么您可以使用OP Ben Humphreys ,不要忘记选择代码搜索选择器...


    Is there a way to grep for something inside a Github project's code?

    I could pull the source and grep it locally, but I was wondering if it's possible through the web interface or a 3rd-party alternative.

    Ideas?

    解决方案

    Update January 2013: a brand new search has arrived!, based on elasticsearch.org:

    A search for stat within the ruby repo will be expressed as stat repo:ruby/ruby, and will now just workTM.
    (the repo name is not case sensitive: test repo:wordpress/wordpress returns the same as test repo:Wordpress/Wordpress)

    Will give:

    And you have many other examples of search, based on followers, or on forks, or...


    Update July 2012 (old days of Lucene search and poor code indexing, combined with broken GUI, kept here for archive):

    The search (based on SolrQuerySyntax) is now more permissive and the dreaded "Invalid search query. Try quoting it." is gone when using the default search selector "Everything":)

    (I suppose we can all than Tim Pease, which had in one of his objectives "hacking on improved search experiences for all GitHub properties", and I did mention this Stack Overflow question at the time ;) )

    Here is an illustration of a grep within the ruby code: it will looks for repos and users, but also for what I wanted to search in the first place: the code!


    Initial answer and illustration of the former issue (Sept. 2012 => March 2012)

    You can use the advanced search GitHub form:

    • Choose Code, Repositories or Users from the drop-down and
    • use the corresponding prefixes listed for that search type.

    For instance, Use the repo:username/repo-name directive to limit the search to a code repository.
    The initial "Advanced Search" page includes the section:

    Code Search:

    The Code search will look through all of the code publicly hosted on GitHub. You can also filter by :

    • the language language:
    • the repository name (including the username) repo:
    • the file path path:

    So if you select the "Code" search selector, then your query grepping for a text within a repo will work:


    What is incredibly unhelpful from GitHub is that:

    • if you forget to put the right search selector (here "Code"), you will get an error message:
      "Invalid search query. Try quoting it."

    • the error message doesn't help you at all.
      No amount of "quoting it" will get you out of this error.

    • once you get that error message, you don't get the sections reminding you of the right association between the search selectors ("Repositories", "Users" or "Language") and the (right) search filters (here "repo:").
      Any further attempt you do won't display those associations (selectors-filters) back. Only the error message you see above...
      The only way to get back those arrays is by clicking the "Advance Search" icon:

    • the "Everything" search selector, which is the default, is actually the wrong one for all of the search filters! Except "language:"...
      (You could imagine/assume that "Everything" would help you to pick whatever search selector actually works with the search filter "repo:", but nope. That would be too easy)

    • you cannot specify the search selector you want through the "Advance Search" field alone!
      (but you can for "language:", even though "Search Language" is another combo box just below the "Search for" 'type' one...)


    So, the user's experience usually is as follows:

    • you click "Advanced Search", glance over those sections of filters, and notice one you want to use: "repo:"
    • you make a first advanced search "repo:jruby/jruby stat", but with the default Search selector "Everything"
      => FAIL! (and the arrays displaying the association "Selectors-Filters" is gone)
    • you notice that "Search for" selector thingy, select the first choice "Repositories" ("Dah! I want to search within repositories...")
      => FAIL!
    • dejected, you select the next choice of selectors (here, "Users"), without even looking at said selector, just to give it one more try...
      => FAIL!
    • "Screw this, GitHub search is broken! I'm outta here!"
      ...
      (GitHub advanced search is actually not broken. Only their GUI is...)

    So, to recap, if you want to "grep for something inside a Github project's code", as the OP Ben Humphreys, don't forget to select the "Code" search selector...

    这篇关于在Github项目中搜索代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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