Including the commit date in the reference
Including the commit date in the reference
Posted Dec 14, 2024 23:05 UTC (Sat) by alx.manpages (subscriber, #145117)Parent article: Facing the Git commit-ID collision catastrophe
Recently, I had to refer to many of the commits in one project I co-maintain, and came up with some notation that's straightforward, and lets me easily see the precise commit I'm referring to:
```
$ cat ~/.gitconfig | grep -A1 'ref ='
ref = show --no-patch --abbrev=12 --date=short --format=format:'%C(auto)%h (%cd,%C(reset) \"%C(white)%s%C(reset)\")'
$ git ref HEAD -3
8821d3ff2dcf (2024-12-09, "lib/fs/readlink/: readlinknul(): Fix return type")
b9d00b64a19f (2024-12-09, "lib/fs/readlink/readlinknul.h: readlinknul(): Silence warning")
205c23bff28f (2024-12-09, "Added option -a for listing active users only, optimized using if aflg,return")
```
That is:
<hash-12-chars> (<commit-date>, "commit-subject")
The combination of 12-char hash and commit date makes it completely unambiguous, and the subject makes it more readable.
A few considerations, compared to `git log --pretty=reference`:
- The commit date is more useful than the author date, because some commits might have been authored years before being finally committed. When looking at the git-log(1), and especially in --graph mode, the dates that will be correlative are the commit dates, which make it easy to search.
- This puts the date before the subject, which makes it easier to find all three fields in a long list of references.
- This includes quotes around the subject, as usual.
So, I now use references like this in commit messages:
Fixes: 419ce14b6f72 (2024-11-01, "lib/fs/readlink/: readlinknul(): Add function")
Posted Dec 15, 2024 15:43 UTC (Sun)
by mgedmin (subscriber, #34497)
[Link] (1 responses)
Posted Dec 16, 2024 23:06 UTC (Mon)
by alx.manpages (subscriber, #145117)
[Link]
I didn't like it though. The author date is useless, as it doesn't serve to find a commit in the log. Also, I prefer having quotes around the subject.
Posted Dec 16, 2024 23:09 UTC (Mon)
by alx.manpages (subscriber, #145117)
[Link]
Fixes: mutt.git b423ebbfa9d2 (1999-01-04, "Make the experimental branch the main trunk.")
I also use this when cherry-picking commits from other projects; that's where this is especially useful.
Including the commit date in the reference
Including the commit date in the reference
Including the commit date in the reference