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 certain push.
I writing a program that needs to keep track of the commits as they are pushed. Because the git log is ordered by the commit date, not the push date, I am not able to see the most recent commits that are pushed. For example, if a user commits to his local repository 2 days before he pushes to the master, that commit will be placed behind 2 days of other commits in the master repository log.
git does not log when things are pushed into a repository (or fetched for that matter), only the two timestamps on the commits themselves, so I don't think there's a reliable way to do this without writing hooks that would store extra metadata somewhere for you, or relying on logging done by git-daemon, ssh, or your ...
you can use git log --graph --all --decorate , it will show where each ref is located (HEAD, master, origin/master etc.) This is my favorite answer because it gives the information EXPLICITLY: "commit XYZ (origin/master)".
It took me an insanely long time to gather scattered information and finally find the very best answer to this question, but now I know I have it. In just two lines, no code and no hooks:
# required for a bare repo git config core.logAllRefUpdates true git reflog --date=local master
Simple at last.
Warning: you probably want to override the default values of gc.reflogExpire
and gc.reflogExpireUnreachable
. Check git help reflog
for details and to understand how and why this works.
The two commands above must be run inside the clone you push to. If that is not possible then an approximation is to run in another, permanent clone:
git fetch origin # often and *regularly* git reflog --date=local origin/master
Never delete this permanent clone or you will lose the dates.
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.
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