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

后端 未结 4 487
迷失自我
迷失自我 2020-12-04 23:16

I use a fairly complex git-log command involving --date-order to get an overview of my repository\'s status; but unfortunately, --date-order<

相关标签:
4条回答
  • 2020-12-04 23:49

    git version 1.8.4 added an --author-date-order argument 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."

    0 讨论(0)
  • 2020-12-04 23:53

    --date-order/--topo-order really 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 always respected, even if your committer/authoring timestamp is in the distant past or future.

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

    0 讨论(0)
  • 2020-12-05 00:01

    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!

    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
    
    0 讨论(0)
  • 2020-12-05 00:04

    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 think you 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 '\15\32' | less -R
    

    You can find this script and others in Git Extras on GitHub.

    0 讨论(0)
提交回复
热议问题