git中有没有办法获取给定提交的推送日期? [英] Is there a way in git to obtain a push date for a given commit?
问题描述
我想知道是否有办法查看与 git 日志中的每个提交相关联的推送日期.如果这是不可能的,有没有办法查看某个推送下的所有提交.
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.
我编写了一个程序,需要在提交时跟踪提交.因为 git log 是按提交日期而不是推送日期排序的,所以我看不到推送的最新提交.例如,如果用户在推送到主存储库前 2 天提交到他的本地存储库,则该提交将被放置在主存储库日志中其他提交的 2 天之后.
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.
推荐答案
我花了很长时间收集零散的信息,终于找到了这个问题的最佳答案,但现在我知道我拥有它.仅仅两行,没有代码也没有钩子:
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
终于简单了.
警告:您可能想要覆盖 gc.reflogExpire
和 gc.reflogExpireUnreachable
的默认值.查看 git help reflog
以了解详细信息并了解其工作原理和原因.
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中有没有办法获取给定提交的推送日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!