From 60294ff62423a371a91442ff88935822021ccd0a Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 16 Aug 2020 06:33:47 -0300 Subject: Add TIL on searching in git --- _tils/2020-08-16-search-in-git.md | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 _tils/2020-08-16-search-in-git.md (limited to '_tils/2020-08-16-search-in-git.md') diff --git a/_tils/2020-08-16-search-in-git.md b/_tils/2020-08-16-search-in-git.md new file mode 100644 index 0000000..b76cdf5 --- /dev/null +++ b/_tils/2020-08-16-search-in-git.md @@ -0,0 +1,51 @@ +--- +title: Search in git +date: 2020-08-16 +layout: til +lang: en +ref: search-in-git +--- + +Here's a useful trio to know about to help you search things in git: + +1. `git show ` +2. `git log --grep='` +3. `git grep '' [commit]` + +## 1. `git show ` + +Show a specific commit and it's diff: + +```shell +git show +# shows the latest commit +git show +# shows an specific +git show v1.2 +# shows commit tagged with v1.2 +``` + +## 2. `git log --grep='` + +Search through the commit messages: + +```shell +git log --grep='refactor' +``` + +## 3. `git grep [commit]` + +Search content in git history: + +```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 +[use git checkout for that][0]. + +[0]: {% link _tils/2020-08-14-browse-a-git-repository-at-a-specific-commit.md %} -- cgit v1.2.3