Skip to content

Commit 39916e0

Browse files
committed
Add Grep For A Pattern On Another Branch as a git til
1 parent dda3b9b commit 39916e0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77
warrant a full blog post. These are mostly things I learn by pairing with
88
smart people at [Hashrocket](http://hashrocket.com/).
99

10-
_507 TILs and counting..._
10+
_508 TILs and counting..._
1111

1212
---
1313

@@ -134,6 +134,7 @@ _507 TILs and counting..._
134134
- [Excluding Files Locally](git/excluding-files-locally.md)
135135
- [Find The Initial Commit](git/find-the-initial-commit.md)
136136
- [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md)
137+
- [Grep For A Pattern On Another Branch](git/grep-for-a-pattern-on-another-branch.md)
137138
- [Grep Over Commit Messages](git/grep-over-commit-messages.md)
138139
- [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md)
139140
- [Intent To Add](git/intent-to-add.md)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Grep For A Pattern On Another Branch
2+
3+
Git has a built-in `grep` command that works essentially the same as the
4+
standard `grep` command that unix users are used to. The benefit of
5+
`git-grep` is that it is tightly integrated with Git.
6+
You can search for occurrences of a pattern on another branch. For example,
7+
if you have a feature branch, `my-feature`, on which you'd like to search
8+
for occurrences of `user.last_name`, then your command would look like this:
9+
10+
```bash
11+
$ git grep 'user\.last_name' my-feature
12+
```
13+
14+
If there are matching results, they follow this format:
15+
16+
```
17+
my-feature:app/views/users/show.html.erb: <%= user.last_name %>
18+
...
19+
```
20+
21+
This formatting is handy because you can easily copy the branch and file
22+
directive for use with [`git-show`](viewing-a-file-on-another-branch.md).
23+
24+
See `man git-grep` for more details.

0 commit comments

Comments
 (0)