1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-06 08:38:01 +00:00

Add Grep For A Pattern On Another Branch as a git til

This commit is contained in:
jbranchaud
2017-02-23 10:11:47 -06:00
parent dda3b9bbc7
commit 39916e0766
2 changed files with 26 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
# Grep For A Pattern On Another Branch
Git has a built-in `grep` command that works essentially the same as the
standard `grep` command that unix users are used to. The benefit of
`git-grep` is that it is tightly integrated with Git.
You can search for occurrences of a pattern on another branch. For example,
if you have a feature branch, `my-feature`, on which you'd like to search
for occurrences of `user.last_name`, then your command would look like this:
```bash
$ git grep 'user\.last_name' my-feature
```
If there are matching results, they follow this format:
```
my-feature:app/views/users/show.html.erb: <%= user.last_name %>
...
```
This formatting is handy because you can easily copy the branch and file
directive for use with [`git-show`](viewing-a-file-on-another-branch.md).
See `man git-grep` for more details.