Skip to content

Commit aafb155

Browse files
committed
Add Reference A Commit Via Commit Message Pattern Matching as a git til.
1 parent b121419 commit aafb155

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
7676
- [List Filenames Without The Diffs](git/list-filenames-without-the-diffs.md)
7777
- [List Untracked Files](git/list-untracked-files.md)
7878
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)
79+
- [Reference A Commit Via Commit Message Pattern Matching](git/reference-a-commit-via-commit-message-pattern-matching.md)
7980
- [Renaming A Branch](git/renaming-a-branch.md)
8081
- [Resetting A Reset](git/resetting-a-reset.md)
8182
- [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Reference A Commit Via Commit Message Pattern Matching
2+
3+
Generally when referencing a commit, you'll use the SHA or a portion of the
4+
SHA. For example with `git-show`:
5+
6+
```
7+
$ git show cd6a63d014
8+
...
9+
```
10+
11+
There are many ways to reference commits though. One way is via regex
12+
pattern matching on the commit message. For instance, if you recently had a
13+
commit with a typo and you had included *typo* in the commit message, then
14+
you could reference that commit like so:
15+
16+
```
17+
$ git show :/typo
18+
Author: Josh Branchaud
19+
Date: Mon Dec 21 15:50:20 2015 -0600
20+
21+
Fix a typo in the documentation
22+
...
23+
```
24+
25+
By using `:/` followed by some text, git will attempt to find the most
26+
recent commit whose commit message matches the text. As I alluded to, regex
27+
can be used in the text.
28+
29+
See `$ man gitrevisions` for more details and other ways to reference
30+
commits.
31+
32+
[Source](https://twitter.com/jamesfublo/status/678906346335428608)

0 commit comments

Comments
 (0)