如何根据作者的时间戳制作 git log 顺序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8576503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:33:58  来源:igfitidea点击:

How can I make git log order based on author's timestamp?

gitsortingtimestampgit-log

提问by ELLIOTTCABLE

I use a fairly complex git-logcommand involving --date-orderto get an overview of my repository's status; but unfortunately, --date-orderseems to use the committerdate, not the authordate. That means that each time I bring my topic branches up to date by rebasing them onto the current upstream, I lose the helpful chronological ordering in my git-logof relative commits in my topic branches (that is, each branch becomes a single long line, because all of its commits got rebased to sequential and nearly-identical committer timestamps.)

我使用了一个相当复杂的git-log命令--date-order来获取我的存储库状态的概览;但不幸的是,--date-order似乎使用提交者日期,而不是作者日期。这意味着每次我通过将主题分支重新设置到当前上游来更新主题分支时,我都会失去git-log主题分支中相对提交中有用的时间顺序(也就是说,每个分支都变成了一条长线,因为所有的提交被重新基于顺序和几乎相同的提交者时间戳。)

If I could get git-logto order commits by the authortimestamp instead of the committertimestamp, this would be solved. Does anybody know of a way to do that?

如果我能得到git-log通过订单提交笔者时间戳,而不是提交者的时间戳,这将得到解决。有人知道这样做的方法吗?



For those visiting this from Google results, you may want to look into josephdpurcell's solution (and in-depth blog post!), below. It's quite excellent, if you're looking for standard git-logstyle output, multi-line, with detailed messages about each commit.

对于从 Google 结果访问此内容的人,您可能需要查看下方 josephdpurcell的解决方案(以及深入的博客文章!)。如果您正在寻找标准git-log样式的输出,多行,并带有有关每次提交的详细消息,那么它非常出色。

Unfortunate, I now need to amend this question, because I'm an idiot and didn't provide more specific information about my use-case: I use git-login “--graphmode,” and I need to make git-logitselfoperate in author-date-order. As far as I've been able to ascertain, this is completely impossible to do from outside git-log, because git-logitselfhandles the graph ordering and printing.

不幸的是,我现在需要修改这个问题,因为我是个白痴,没有提供关于我的用例的更具体的信息:我git-log在“--graph模式”下使用,我需要让git-log自己按作者日期顺序运行. 据我所知,从外部完全不可能做到这一点git-log,因为git-log它本身处理图形排序和打印。

A script, or patch for git-log, may be necessary, it seems. I'll leave this open until somebody can either 1. write such a script, or 2. we can talk the gitauthors into including a --author --date-ordercombination of flags. (=

git-log似乎需要一个脚本或补丁。我将保持开放,直到有人可以 1. 编写这样的脚本,或 2. 我们可以与git作者讨论包含--author --date-order标志的组合。(=



For reference, here's what my current glogfunction's output looks like, and what I need to re-order:

作为参考,这是我当前glog函数的输出,以及我需要重新排序的内容:

glog output

日志输出

回答by M Somerville

git version 1.8.4 added an --author-date-orderargument to git log; according to the release notes, "the output is topologically sorted and commits in parallel histories are shown intermixed together based on the author timestamp."

git version 1.8.4 添加了一个--author-date-order参数git log;根据发行说明,“输出按拓扑排序,并根据作者时间戳将并行历史中的提交混合在一起显示。”

回答by josephdpurcell

Okay, this took me a very long time to figure out (details). In short, I found many examples that were either incomplete or incorrect. The following command does what I thinkyou would expect:

好的,这花了我很长时间才弄明白(细节)。简而言之,我发现了许多不完整或不正确的例子。以下命令执行我认为您期望的操作:

$ git log --pretty="format:%at %C(yellow)commit %H%Creset\nAuthor: %an <%ae>\nDate: %aD\n\n %s\n" | sort -r | cut -d" " -f2- | sed -e "s/\\n/\`echo -e '\n\r'`/g" | tr -d '' | less -R

You can find this script and others in Git Extrason GitHub.

您可以在 GitHub 上的Git Extras 中找到此脚本和其他脚本。

回答by j?rgensen

--date-order/--topo-orderreally just controls the ordering of commits in a revision list when you are viewing multiple branches running alongside another. The "x is-a-parent of y" relationship is alwaysrespected, even if your committer/authoring timestamp is in the distant past or future.

--date-order/--topo-order实际上只是在您查看多个分支并排运行时控制修订列表中提交的顺序。“x 是 y 的父级”关系始终受到尊重,即使您的提交者/创作时间戳是在遥远的过去或未来。

You'd need something like git log --pretty="format:%at %H" | sort -gand then feed the hashes back into git log.

您需要类似的东西git log --pretty="format:%at %H" | sort -g,然后将哈希值送回git log.

回答by Nate

Building off of what j?rgensen suggested there is a "one-liner" solution that may give you what you are looking for. Formatted here for easier viewing. Improvements are welcomed!

建立在 j?rgensen 建议的基础上,有一个“单线”解决方案可以为您提供所需的东西。在这里格式化以便于查看。欢迎改进!

SORTED_GIT_LOGS=$(git log --pretty="format:%at %H" | sort -g | cut -d' ' -f2); \
    IFS=$(echo -en "\n\b"); for LOG in $SORTED_GIT_LOGS; do \
        git show --name-only $LOG; \
    done | less