Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refer to a previous commit in git commit message

Tags:

git

github

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?

like image 846
Joel Avatar asked Nov 27 '12 04:11

Joel


People also ask

How do I show previous changes made with commit message?

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 .

How do I reference a specific commit?

To reference a commit, simply write its SHA-hash, and it'll automatically get turned into a link.

How do you jump to a previous commit?

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 .


2 Answers

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
like image 95
Michael Shimmins Avatar answered Sep 18 '22 13:09

Michael Shimmins


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> 
like image 45
Vser Avatar answered Sep 17 '22 13:09

Vser