From aafb1553fae107e52ccf26f28b329b587ec73b04 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 21 Dec 2015 17:34:13 -0600 Subject: [PATCH] Add Reference A Commit Via Commit Message Pattern Matching as a git til. --- README.md | 1 + ...mit-via-commit-message-pattern-matching.md | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 git/reference-a-commit-via-commit-message-pattern-matching.md diff --git a/README.md b/README.md index 22934e1..166955d 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/git/reference-a-commit-via-commit-message-pattern-matching.md b/git/reference-a-commit-via-commit-message-pattern-matching.md new file mode 100644 index 0000000..301cfd5 --- /dev/null +++ b/git/reference-a-commit-via-commit-message-pattern-matching.md @@ -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)