且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何重新整理并保持提交按时间顺序排列?

更新时间:2022-12-12 13:10:20

您的问题有点不确定,因为git log始终对输出进行排序,但

Your question is a bit underspecified, because git log always sorts its output, but it takes options telling it how to sort:

提交订购

默认情况下,提交将按相反的时间顺序显示.

By default, the commits are shown in reverse chronological order.

--date-order

    在显示所有子项之前不显示任何父母,否则以提交时间戳记顺序显示提交.
    Show no parents before all of its children are shown, but otherwise show commits in the commit timestamp order.

--author-date-order

    在显示所有子项之前不显示任何父母,否则以作者时间戳顺序显示提交.
    Show no parents before all of its children are shown, but otherwise show commits in the author timestamp order.

--topo-order

    在显示所有子项之前不显示任何父母,并避免在多行历史记录中混合显示提交内容.
    Show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed.

因此,没有任何选项,git log会按时间顺序显示提交,无论如何.

Hence, with no options, git log shows commits in chronological order no matter what.

思考,您要问的是,您如何更改重新设置的提交上的时间戳.默认情况下,rebase会保留时间戳.

I think what you're asking is, instead, how you can change the time stamps on the rebased commits. By default, rebase preserves the time stamps.

请注意,每次提交有两个 时间戳:作者日期和提交者日期.

Note that there are two time stamps on each commit: the author date, and the committer date.

rebase文档描述了这两个选项:

--committer-date-is-author-date--ignore-date

    这些标志被传递给git am,以轻松更改重新基于基础的提交的日期(请参见git-am(1)).与--interactive选项不兼容.
    These flags are passed to git am to easily change the dates of the rebased commits (see git-am(1)). Incompatible with the --interactive option.

咨询 git am文档对此有更好的描述:

Consulting the git am documentation gives a better description of these:

--committer-date-is-author-date

    默认情况下,该命令将电子邮件中的日期记录为提交作者日期,并使用提交创建的时间作为提交者日期.这样,用户可以使用与作者日期相同的值来说谎有关提交者的日期.
    By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date. This allows the user to lie about the committer date by using the same value as the author date.

--ignore-date

    默认情况下,该命令将电子邮件中的日期记录为提交作者日期,并使用提交创建的时间作为提交者日期.这样,用户可以通过使用与提交者日期相同的值来谎言作者日期.
    By default the command records the date from the e-mail message as the commit author date, and uses the time of commit creation as the committer date. This allows the user to lie about the author date by using the same value as the committer date.

您可以使用带有git logfuller格式(例如(git log --format=fuller))查看作者和提交者的日期.

You can see both author and committer dates using the fuller format with git log, for instance (git log --format=fuller).

我相信您想使用--ignore-date,这将使每个基于重新提交的提交从现在开始"进行(假定我正确地解释了您的问题!).

I believe you want to use --ignore-date, which makes each rebased commit happen "as of right now" (this assumes I'm interpreting your question correctly!).