本文介绍了如何重新整理并保持提交按时间顺序排列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在master分支上重新建立一个分支,但以使所有提交都按时间顺序显示在git日志中的方式.如果没有git rebase --interactive并手动重新排列提交,是否可以实现?

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 --interactive and rearranging the commits manually?

背景:我正在使用git跟踪服务器场的人偶配置. master分支始终处于已知的良好状态,以便所有现有服务器都可以从p master服务器检索其配置.

Background: I am using git for keeping track of the puppet configuration of a server farm. The master branch is always in a known good state, so that all existing servers can retrieve their configuration from the puppet master server.

每个新服务器都有其自己的分支,因此,每当我在新服务器的配置上进行工作(例如更改域名,配置SSL证书)时,我都会检出其分支并提交所有配置.

Each new server gets its own branch, so whenever I work on the configuration of a new server, such as changing a domain name, configuring an SSL certificate I check out its branch and commit all configurations.

完成新配置后,我将更改重新基于master分支:

After the new configuration is completed, I rebase the changes onto the master branch:

# git checkout new_config
Switched to branch 'new_config'
# git rebase master
First, rewinding head to replay your work on top of it...
Applying: fix routing rules
Applying: fix netmask
Applying: configure new ip address
# git checkout master
Switched to branch 'master'
# git merge new_config
Updating 21a3120..b0b79d7
Fast-forward
 files/custom/xxxx |   45 +++++++++++++++++++++++++++++++++++++++++++++
 files/custom/yyyy |   38 --------------------------------------
 manifests/site.pp |    6 +++---
 3 files changed, 48 insertions(+), 41 deletions(-)
#

新提交现在位于日志的顶部,但是它们具有其原始(过去)日期.看起来像这样:

The new commits are now on top of the log but they have their original (past) dates. It looks like this:

commit b0b79d7924ec97e367664ccc26aaf0021916a30d
Author:
Date:   Sun Jul 12 17:14:41 2015 +0200

    configure new ip address

commit f60d00abd57d6b8582f49bf1322efb88d44ee86e
Author:
Date:   Fri Jul 10 13:19:45 2015 +0200

    fix netmask

commit 6eaae6c328faf55e5725f65a947bbb23ea29b166
Author:
Date:   Fri Jun 12 14:05:25 2015 +0200

    fix routing rules

commit 21a31200e6694c640b2cb526d773af11cd703ff1
Author:
Date:   Wed Jul 15 15:08:41 2015 +0200

    (most recent commit on master before rebase)

commit a7fa9cfa9c317fbbeb7dac8a89009c7d935fdd11
Author:
Date:   Wed Jul 15 11:56:59 2015 +0200

    (second most recent commit on master)

请注意,分支提交的旧时间戳是如何显示在日志的顶部的,而不是根据它们的提交日期在日志中向下合并的.我必须运行另一个git rebase --interactive来重新排列提交,以便我的日志文件按时间顺序显示所有提交.

Note how the old timestamps of the branch commits show up at the top of the log, instead of being merged further down in the log according to their commit dates. I have to run another git rebase --interactive to rearrange the commits so that my log file shows all commits in chronological order.

推荐答案

您的问题有点不确定,因为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文档描述了这两个选项:

    这些标志被传递给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:

    默认情况下,该命令将电子邮件中的日期记录为提交作者日期,并使用提交创建的时间作为提交者日期.这样,用户可以使用与作者日期相同的值来说谎有关提交者的日期.
    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!).

这篇关于如何重新整理并保持提交按时间顺序排列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:24