1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Reference A Commit Via Commit Message Pattern Matching as a git til.

This commit is contained in:
jbranchaud
2015-12-21 17:34:13 -06:00
parent b12141953a
commit aafb1553fa
2 changed files with 33 additions and 0 deletions

View File

@@ -76,6 +76,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
- [List Filenames Without The Diffs](git/list-filenames-without-the-diffs.md)
- [List Untracked Files](git/list-untracked-files.md)
- [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md)
- [Reference A Commit Via Commit Message Pattern Matching](git/reference-a-commit-via-commit-message-pattern-matching.md)
- [Renaming A Branch](git/renaming-a-branch.md)
- [Resetting A Reset](git/resetting-a-reset.md)
- [Single Key Presses in Interactive Mode](git/single-key-presses-in-interactive-mode.md)

View File

@@ -0,0 +1,32 @@
# Reference A Commit Via Commit Message Pattern Matching
Generally when referencing a commit, you'll use the SHA or a portion of the
SHA. For example with `git-show`:
```
$ git show cd6a63d014
...
```
There are many ways to reference commits though. One way is via regex
pattern matching on the commit message. For instance, if you recently had a
commit with a typo and you had included *typo* in the commit message, then
you could reference that commit like so:
```
$ git show :/typo
Author: Josh Branchaud
Date: Mon Dec 21 15:50:20 2015 -0600
Fix a typo in the documentation
...
```
By using `:/` followed by some text, git will attempt to find the most
recent commit whose commit message matches the text. As I alluded to, regex
can be used in the text.
See `$ man gitrevisions` for more details and other ways to reference
commits.
[Source](https://twitter.com/jamesfublo/status/678906346335428608)