how to rebase and keep commits in chronological order?

后端 未结 2 754
终归单人心
终归单人心 2021-02-04 08:55

I would like to rebase a branch on the master branch but in such a way that all commits show up in chronological order in the git log. Is this possible without git rebase

2条回答
  •  迷失自我
    2021-02-04 09:26

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

    Commit Ordering

    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.

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

    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.


    The rebase documentation describes these two options:

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

      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.

    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.

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

    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!).

提交回复
热议问题