30

I want to search a repository for any files that end in *Test.java* but if I search for *Test.java* I just get files that contain that exact string.

I can't find any information anywhere that suggests this is possible. Is this just due to limitations of indexing such an enormous amount of data?

I'd like to find a way to search a repo for all classes ending in Test.

slugmandrew
  • 1,776
  • 2
  • 25
  • 45
  • 3
    You might want to try out the filefinder by pressing `T` in the Tree view and entering your search. – TimWolla Mar 28 '14 at 13:51
  • Tree view? Are you talking about the github website here? – slugmandrew Mar 28 '14 at 14:16
  • I do. Open this page: https://github.com/mirrors/linux/ and then hit the `T` key on your keyboard. – TimWolla Mar 28 '14 at 14:56
  • @TimWolla was right. You should post this as an answer because it's the right one. – mttdbrd Mar 28 '14 at 16:18
  • It's good, but not quite right. Still doesn't allow a proper wildcard search - beginning with, ending with etc. I guess it just doesn't exist! – slugmandrew Mar 28 '14 at 16:38
  • @slugmandrew It does do wildcards. It uses regular expressions. See the new edit to my answer below. – mttdbrd Mar 28 '14 at 16:42
  • It's not the same thing though. Say I want to find files that start with `My` and end in `Test.java` I type `My*Test.java` which should then return `MyFirstTest.java`, `MySecondTest.java` etc. The regex results are clearly very useful though. – slugmandrew Mar 28 '14 at 16:59
  • This question appears to be off-topic because it is about using the GitHub site, and not directly programming related. – Abizern Mar 28 '14 at 17:02
  • @slugmandrew Just type MyTest.java and it'll return both. :) – mttdbrd Mar 28 '14 at 17:08
  • 2
    @Abizern I disagree. The GitHub site is a tool used widely by programmers. Locating files is sure to be of interest to many programmers. – mttdbrd Mar 28 '14 at 17:09
  • Interest, yes. Directly programming related, no. We all use computers yet hardware questions aren't on-topic. We all use Search Engines, but I'd vote to close questions about using those. – Abizern Mar 28 '14 at 17:11
  • @mttdbrd Yes it will, but it will also return anything else with an `m` and a `y` in the path/filename :P – slugmandrew Mar 28 '14 at 17:18
  • @Abizern Sheesh. Should I have posted it in webapps or superuser then? What do you suggest? – slugmandrew Mar 28 '14 at 17:19
  • Github has a support page. What next? questions about posting code snippets on Twitter? Another tool widely used by programmers. – Abizern Mar 28 '14 at 18:24
  • @mttdbrd I just added my answer about the file finder. Thanks! – TimWolla Mar 28 '14 at 19:57

2 Answers2

13

The easiest way to find a file in a repository is to use the file finder. You can activate it at any time when you are in repository view by pressing t. See this screenshot from the official annoucement:

enter image description here

The file finder will perform some fuzzy matching using the characters you input into the "search box".

TimWolla
  • 31,849
  • 8
  • 63
  • 96
6

Check out the search syntax page:

https://help.github.com/articles/search-syntax

And searching in repositories:

https://help.github.com/articles/searching-repositories

For this particular one:

Test.java in:name extension:java language: java 

Edit 1:

Here's a picture to explain how to view code matches instead of repository matches:

enter image description here

Edit 2:

Turns out the comment above was right. This is what the GitHub people say:

Hi,

The easiest method for finding files within a repository is to use the file finder:

https://github.com/blog/793-introducing-the-file-finder

You can also use the "in:" search qualifier which allows you to tell search to match filenames as well:

https://help.github.com/articles/searching-code#search-in

Hope that helps!

Edit 3:

Although it doesn't use wildcards as we're used to, it uses regular expressions to find substrings of the strings you type. See below, I typed "SandTest.java" and it produced wild-card like results.

enter image description here

ahmadali shafiee
  • 4,350
  • 12
  • 56
  • 91
mttdbrd
  • 1,791
  • 12
  • 17
  • Hmm. `Test.Java in:name` actually searched for repositories with test in the repository name. I need something like `Test.java in:filename` bit it seems that for code there is only the options to search the path or file contents, not the actual filename itself: https://help.github.com/articles/searching-code – slugmandrew Mar 28 '14 at 14:03
  • extension:java searches filenames with .java extension. Now to restrict it to just files with that name.... – mttdbrd Mar 28 '14 at 14:09
  • Test in:name extension:java language:java returns a lot of stuff, not necessarily restricted to Java.... – mttdbrd Mar 28 '14 at 14:13
  • It's strange huh? It seems that the engine is mainly geared for searching for actual lines of code, or whole repos. – slugmandrew Mar 28 '14 at 14:14
  • It's odd. Even Google won't find an exact filename on site:github.com. It finds all kinds of other stuff. It seems like filenames are excluded from full-text search; it only searches file contents. – mttdbrd Mar 28 '14 at 14:22
  • I think you should give me an upvote for such an excellent question ;) – slugmandrew Mar 28 '14 at 14:23
  • Done. It's a tough one. – mttdbrd Mar 28 '14 at 14:25
  • @slugmandrew Oh, wait. If you click the "<> Code" item in the box on the upper left of the page instead of "[] Repositories" you get just files. This gets a lot of them: Test.java in:name extension:java language:java. There's still extra garbage because some people have "test.java" packages and files named "TestJava." Finds over 4,000,000 files. – mttdbrd Mar 28 '14 at 14:29
  • @slugmandrew And how about an upvote, you know, for the effort? – mttdbrd Mar 28 '14 at 14:30
  • I actually just want to search a single repo. This https://github.com/ArcBees/GWTP/search?q=test+in%3Aname isn't too bad, but it's still finding the class names inside the files rather than the filenames themselves. – slugmandrew Mar 28 '14 at 15:17
  • 1
    @slugmandrew I put in a help request at GitHub. I've had this exact problem before. I'll let you know what they say. – mttdbrd Mar 28 '14 at 15:27
  • @slugmandrew See the new edit above. There's a new file-finder. TimWalla was right! – mttdbrd Mar 28 '14 at 16:14
  • @slugmandrew To use it, you go to the repository and without clicking in the search box, just type t. It takes you to a new page. Without clicking anything there, just type Test.java. Magic! – mttdbrd Mar 28 '14 at 16:17
  • 1
    There is: in:path in:path,file (in:file is the default). I find "in:path" does not work at the org-level (org:abc) without extension:abc. in-syntax: https://docs.github.com/en/free-pro-team@latest/github/searching-for-information-on-github/searching-code#search-by-the-file-contents-or-file-path – Curtis Yallop Nov 12 '20 at 21:12
  • 1
    There is also: path:abc and filename:abc (which work at org-level eg org:abc) https://docs.github.com/en/free-pro-team@latest/github/searching-for-information-on-github/searching-code#search-by-file-location – Curtis Yallop Nov 12 '20 at 21:19