summaryrefslogtreecommitdiff
path: root/src/content/tils/2020/08/16/git-search.adoc
blob: 26e617d8f74950d2a06ab996a50a887dedc0b7bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
= Search in git
:categories: git

Here's a useful trio to know about to help you search things in git:

. `git show <commit>`
. `git log --grep='<regexp>'`
. `git grep '<regexp>' [commit]`

== 1. `git show <commit>`

Show a specific commit and it's diff:

[source,shell]
----
git show
# shows the latest commit
git show <commit>
# shows an specific <commit>
git show v1.2
# shows commit tagged with v1.2
----

== 2. `git log --grep='<regexp>'`

Search through the commit messages:

[source,shell]
----
git log --grep='refactor'
----

== 3. `git grep '<regexp>' [commit]`

:browse-article: link:../14/browse-git.html

Search content in git history:

[source,shell]
----
git grep 'TODO'
# search the repository for the "TODO" string
git grep 'TODO' $(git rev-list --all)
# search the whole history for "TODO" string
----

And if you find an occurrence of the regexp in a specific commit and you want to
browse the repository in that point in time, you can {browse-article}[use git
checkout for that].