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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…