How do I search all Git branches of a project for a file name?
I remember part of the filename (just the ending), so I'd like to be able to search for something like *_robot.php
across all branches, and see which files match that. I'd preferably like to have it search history, and not just the HEADs of branches.
As stated, use gitk --all, then in View | New view, enable All Branches. Then set your search criteria: filenames (with wild cards) in the penultimate field. Finally: OK.
`git grep` command is used to search in the checkout branch and local files. But if the user is searching the content in one branch, but the content is stored in another branch of the repository, then he/she will not get the searching output.
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands.
This is one way:
git log --all --name-only --pretty=format: | sort -u | grep _robot.php
Here is a simpler variation on @manojlds's solution: Git can indeed directly consider all the branches (--all
), print the names of their modified files (--name-only
), and only these names (--pretty=format:
).
But Git can also first filter certain file names (regular expression) by putting the file name regular expression after the --
separator:
git log --all --name-only --pretty=format: -- <file_name_regexp> | sort -u
So, you can directly do:
git log --all --name-only --pretty=format: -- _robot.php | sort -u
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With