mirror of
https://github.com/jbranchaud/til
synced 2026-01-08 01:28:02 +00:00
Add Grep For A Pattern On Another Branch as a git til
This commit is contained in:
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
|
|||||||
warrant a full blog post. These are mostly things I learn by pairing with
|
warrant a full blog post. These are mostly things I learn by pairing with
|
||||||
smart people at [Hashrocket](http://hashrocket.com/).
|
smart people at [Hashrocket](http://hashrocket.com/).
|
||||||
|
|
||||||
_507 TILs and counting..._
|
_508 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -134,6 +134,7 @@ _507 TILs and counting..._
|
|||||||
- [Excluding Files Locally](git/excluding-files-locally.md)
|
- [Excluding Files Locally](git/excluding-files-locally.md)
|
||||||
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
- [Find The Initial Commit](git/find-the-initial-commit.md)
|
||||||
- [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md)
|
- [Grab A Single File From A Stash](git/grab-a-single-file-from-a-stash.md)
|
||||||
|
- [Grep For A Pattern On Another Branch](git/grep-for-a-pattern-on-another-branch.md)
|
||||||
- [Grep Over Commit Messages](git/grep-over-commit-messages.md)
|
- [Grep Over Commit Messages](git/grep-over-commit-messages.md)
|
||||||
- [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md)
|
- [Ignore Changes To A Tracked File](git/ignore-changes-to-a-tracked-file.md)
|
||||||
- [Intent To Add](git/intent-to-add.md)
|
- [Intent To Add](git/intent-to-add.md)
|
||||||
|
|||||||
24
git/grep-for-a-pattern-on-another-branch.md
Normal file
24
git/grep-for-a-pattern-on-another-branch.md
Normal 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.
|
||||||
Reference in New Issue
Block a user