更改 git 分支基础时更改时间戳

发布于 2024-08-07 13:08:37 字数 170 浏览 3 评论 0 原文

在公开分支之前,我已经重新组织了分支中的提交,导致提交的时间戳顺序混乱。我宁愿他们都在今天,中间只有几秒钟。

显然这些时间戳也不正确,但由于这是事情公开的时间,所以我更喜欢它而不是混乱的历史,从时间角度来看。

那么我如何告诉 git 在变基时创建新的时间戳?

I have reorganized the commits in a branch before it is going to be made public causing the timestamps of the commits to be in an mixed up order. I would rather have them be all be today with only seconds in between.

Obviously these time stamps won't be correct either, but since this is the time when things go public I prefer that over a mixed up history, time-wise.

So how do I tell git to create new timestamps while rebasing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

断肠人 2024-08-14 13:08:38

在我的例子中,将时间戳更改为 CommitDate 值,因此在 gitweb 中,一堆几个月前的提交显示为 4 天前。我找到了具有正确日期的最后一次提交,并执行了以下操作:

$ git rebase --committer-date-is-author-date SHA

In my case rebasing changed timestamps to CommitDate value, so in gitweb a bunch of months old commits showed up as 4 days old. I found the last commit with the correct date and did:

$ git rebase --committer-date-is-author-date SHA
万劫不复 2024-08-14 13:08:38

来自评论:

--interactive选项不兼容

实际上...它不再与 Git 2.29 (Q4 2020) 不兼容:“git rebase -i"(man) 了解更多选项
兼容的选项:

  • --interactive/-i
  • --root

请参阅 提交 6160b2e(2020 年 8 月 26 日),作者:Junio C Hamano (gitster)
请参阅提交 2712669(2020 年 8 月 17 日)和 提交 ef484ad(2020 年 7 月 13 日),作者:罗希特·阿希瓦尔 (r1walz)
请参阅提交a3894aa提交 7573cec, 提交 e8cbe21(2020 年 8 月 17 日)作者:Phillip Wood (phillipwood)
(由 Junio C Hamano -- gitster -- 合并于 提交 9c31b19,2020 年 9 月 3 日)

rebase -i:支持- -忽略日期

原始补丁作者:Rohit Ashiwal
签字人:菲利普·伍德

Rebase 通过两个不同的后端实现 - “apply”和“merge”,每个后端都支持一组不同的选项。

特别是,应用后端支持由 'git am(man )' 未在合并后端实现。
这意味着可用的选项根据使用的后端而不同,这令人困惑。

此补丁在合并后端添加了对 --ignore-date 选项的支持。

此选项使用当前时间作为作者日期,而不是在重写提交时重用原始作者日期。
我们小心地以与应用后端相同的方式处理 --ignore-date--committer-date-is-author-date 的组合。

和:

rebase:添加--重置-作者日期

帮助者:Junio C Hamano
签字人:Rohit Ashiwal

之前的提交为 rebase -i 引入了 --ignore-date 标志,但名称相当模糊,因为它没有说明作者日期还是提交者日期被忽略。
添加别名以传达准确的目的。

--重置作者日期

另外:

rebase -i:支持 --committer-日期是作者日期

原始补丁作者:Rohit Ashiwal
签字人:菲利普·伍德

此补丁在合并后端添加了对 --committer-date-is-author-date 选项的支持。
此选项使用正在重写的提交的作者日期作为创建新提交时的提交者日期。

git rebase 现在包含在其

--committer-date-is-author-date

不要使用当前时间作为提交者日期,而是使用
提交的作者日期被重新定位为提交者
日期。
此选项意味着--force-rebase

git rebase 还包含在其

--忽略日期:

此标志传递给“git am”以更改作者日期
每个重新调整基数的提交(请参阅 git am)。


请注意,在 2.29(上文)中,“rebase”和“am”的“--committer-date-is-author-date”选项" 子命令错误地丢失了电子邮件地址,该问题已通过 Git 2.29.1(2020 年第 4 季度)进行更正。

请参阅提交 5f35edd提交 16b0bb9, 提交56706db(2020 年 10 月 23 日)作者:Jeff King (peff)
(由 Junio C Hamano -- gitster -- 合并于 提交 f34687d,2020 年 10 月 26 日)

am:使用 修复损坏的电子邮件--committer-date-is-author-date

签字人:杰夫·金

提交e8cbe2118aam:停止导出GIT_COMMITTER_DATE, 2020-08-17) 重写了设置提交者日期的代码以使用 fmt_ident(),而不是设置环境变量并让 commit_tree()处理它。
但它引入了两个错误:

  • 我们使用作者电子邮件字符串而不是提交者电子邮件
  • 在解析提交者身份时,我们使用了错误的变量来计算电子邮件的长度,导致它始终是零长度字符串

此提交修复了这两个问题,这导致我们通过变基“apply”后端对此选项的测试现在成功。

和:

rebase:使用 --committer 修复损坏的电子邮件-日期是作者日期

报告者:VenomVendor
签字人:杰夫·金

提交7573cec52c(“rebase -i:支持--committer-date-is -author-date", 2020-08-17, Git v2.29.0-rc0 -- 合并batch #13 中列出的 a>)从 builtin/am.c
这样做时,它复制了一个错误,即我们总是将电子邮件设置为空字符串。

我们在之前的提交中修复了 git-am 中的版本;此提交修复了复制的代码。

From comments:

Incompatible with the --interactive option

Actually... it is no longer incompatible with Git 2.29 (Q4 2020): "git rebase -i"(man) learns a bit more options.
Options which are compatible with:

  • --interactive/-i
  • --root!

See commit 6160b2e (26 Aug 2020) by Junio C Hamano (gitster).
See commit 2712669 (17 Aug 2020), and commit ef484ad (13 Jul 2020) by Rohit Ashiwal (r1walz).
See commit a3894aa, commit 7573cec, commit e8cbe21 (17 Aug 2020) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 9c31b19, 03 Sep 2020)

rebase -i: support --ignore-date

Original-patch-by: Rohit Ashiwal
Signed-off-by: Phillip Wood

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options.

In particular the apply backend supports a number of options implemented by 'git am(man)' that are not implemented in the merge backend.
This means that the available options are different depending on which backend is used which is confusing.

This patch adds support for the --ignore-date option to the merge backend.

This option uses the current time as the author date rather than reusing the original author date when rewriting commits.
We take care to handle the combination of --ignore-date and --committer-date-is-author-date in the same way as the apply backend.

And:

rebase: add --reset-author-date

Helped-by: Junio C Hamano
Signed-off-by: Rohit Ashiwal

The previous commit introduced --ignore-date flag to rebase -i, but the name is rather vague as it does not say whether the author date or the committer date is ignored.
Add an alias to convey the precise purpose.

--reset-author-date

Also:

rebase -i: support --committer-date-is-author-date

Original-patch-by: Rohit Ashiwal
Signed-off-by: Phillip Wood

This patch adds support for the --committer-date-is-author-date option to the merge backend.
This option uses the author date of the commit that is being rewritten as the committer date when the new commit is created.

git rebase now includes in its man page:

--committer-date-is-author-date:

Instead of using the current time as the committer date, use
the author date of the commit being rebased as the committer
date.
This option implies --force-rebase.

git rebase also includes in its man page:

--ignore-date:

This flag is passed to 'git am' to change the author date
of each rebased commit (see git am).


Note that in 2.29 (above), "--committer-date-is-author-date" option of "rebase" and "am" subcommands lost the e-mail address by mistake, which has been corrected with Git 2.29.1 (Q4 2020).

See commit 5f35edd, commit 16b0bb9, commit 56706db (23 Oct 2020) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit f34687d, 26 Oct 2020)

am: fix broken email with --committer-date-is-author-date

Signed-off-by: Jeff King

Commit e8cbe2118a (am: stop exporting GIT_COMMITTER_DATE, 2020-08-17) rewrote the code for setting the committer date to use fmt_ident(), rather than setting an environment variable and letting commit_tree() handle it.
But it introduced two bugs:

  • we use the author email string instead of the committer email
  • when parsing the committer ident, we used the wrong variable to compute the length of the email, resulting in it always being a zero-length string

This commit fixes both, which causes our test of this option via the rebase "apply" backend to now succeed.

And:

rebase: fix broken email with --committer-date-is-author-date

Reported-by: VenomVendor
Signed-off-by: Jeff King

Commit 7573cec52c ("rebase -i: support --committer-date-is-author-date", 2020-08-17, Git v2.29.0-rc0 -- merge listed in batch #13) copied the committer ident-parsing code from builtin/am.c.
And in doing so, it copied a bug in which we always set the email to an empty string.

We fixed the version in git-am in the previous commit; this commit fixes the copied code.

原来是傀儡 2024-08-14 13:08:37

使用 --ignore-date

git rebase --ignore-date

Use --ignore-date:

git rebase --ignore-date
酒浓于脸红 2024-08-14 13:08:37

有以下几种方式

  1. 普通rebase

    git rebase --ignore-date
    
  2. 交互式变基

    git rebase -i master
    git commit --amend --date=now
    git push origin <分支> -f
    

There are the following ways

  1. Normal rebase

    git rebase --ignore-date
    
  2. Interactive rebase

    git rebase -i master
    git commit --amend --date=now
    git push origin <branch> -f
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文