Is there a convention for referring to a previous commit in a git commit message?
Example commit message:
Fixed bug such and such introduced in a1b2c3e4
In particular, is there a convention that github.com will understand, and convert to a link?
If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .
To reference a commit, simply write its SHA-hash, and it'll automatically get turned into a link.
To jump back to a previous commit, first find the commit's hash using git log . This places you at commit 789abcd . You can now make new commits on top of this old commit without affecting the branch your head is on. Any changes can be made into a proper branch using either branch or checkout -b .
Yup - GitHub will pick up references to SHAs and users/repos patterns using the GitHub Flavored Markdown
Specifically about linking to commits:
A bit of the GitHub spice
In addition to the changes in the previous section, certain references are auto-linked:
- SHA: be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2
- User@SHA ref: mojombo@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2
- User/Project@SHA: mojombo/god@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2
- #Num: #1
- User/#Num: mojombo#1
- User/Project#Num: mojombo/god#1
Guys at git answers the question this way:
If you want to reference a previous commit in the history of a stable branch, use the format "abbreviated hash (subject, date)", like this:
Commit f86a374 (pack-bitmap.c: fix a memleak, 2015-03-30) noticed that ...
The "Copy commit summary" command of gitk can be used to obtain this format (with the subject enclosed in a pair of double-quotes), or this invocation of git show:
git show -s --pretty=reference <commit>
or, on an older version of Git without support for --pretty=reference:
git show -s --date=short --pretty='format:%h (%s, %ad)' <commit>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With