I am wondering if there is a way to view a push date associated with each commit in the git log. If that is not possible, is there a way to see all the commits under a cert
Git is a distributed version control system, so you have to carefully define what you mean by "push date". For example, suppose user A pushes some commits to user B's repository. Some point later, user B pushes those same commits to a third repository. Which date are you interested in?
I'm speculating that you have a shared repository and want the users of that shared repository to be able to determine when something was published to the repository. If that's true, you'll have to collect that information in the shared repository.
Unfortunately, there's no way to append the date to the commit messages. That would change the commit ID (which is a SHA1 hash of the contents), causing all sorts of problems.
Fortunately, Git has a (relatively new) feature called notes. This feature allows you to attach arbitrary text to commits, which git log
can display. Notes can be edited and shared with others.
You can use the notes feature to attach a "this commit was received on [date]" message to each commit as it is received by the shared repository.
See git help notes
for details.
Here's the approach I recommend:
post-receive
hook on your shared repository to walk each newly reachable commit for each updated reference.For each commit, append something like "[user] of [repository_url] added this commit to [ref] on [date]" to the commit's note.
You may want to use a notes ref dedicated to this purpose (like refs/notes/received-on
) instead of the default refs/notes/commits
. This will prevent conflicts with notes created for other purposes.
receive
hook to deny updates to your notes reference (to keep users from accidentally or purposely messing with the notes).Tell all the users to run the following commands from inside their working tree:
# Fetch all notes from the shared repository.
# Assumes the shared repository remote is named 'origin'.
git config --add remote.origin.fetch '+refs/notes/*:refs/remote-notes/origin/*'
# Show all notes from the shared repository when running 'git log'
git config --add notes.displayRef 'refs/remote-notes/origin/*'
This step is necessary because Git ignores non-branch, non-tag references in upstream repositories by default.
The above assumes that references are only advanced, never deleted or force-updated. You'll probably want to have the post-receive
hook also append "removed on [date]" notes to handle these cases.