远程提交日期与本地不对应

huangapple go评论72阅读模式
英文:

Remote commit dates not corresponding with local

问题

The commit dates on the local and remote branch diverge due to the nature of interactive rebasing. When you squash or fixup commits during interactive rebase, you are creating new commits with new commit IDs and timestamps. As a result, the commit dates on the remote branch correspond to the date of the rebasing and pushing, not the original commit dates.

There is no direct way to change Git/GitHub's behavior to make the commit dates correspond after interactive rebasing. Once commits are pushed to the remote repository, their timestamps are set and cannot be easily altered without causing issues with the repository's history integrity.

If maintaining the original commit dates is crucial for your workflow, consider avoiding interactive rebasing or squashing commits before pushing to the remote repository. Alternatively, communicate the changes in commit history to your team to avoid confusion regarding the timestamps.

英文:

I recently rebased my most recent commits to my master branch interactively (rebase -i). I squashed multiple commits into just two, discarding unneeded commit messages (fixup), and subsequently pushed to remote master (on GitHub).

What I noticed is that the commit dates in the remote repo does not correspond to the date of the commit (as provided by git log). Rather the commit dates on the remote branch correspond to the date of rebasing and pushing. From what I can find, the commit history on the remote repo is supposed to correspond to the local one, but the commit dates in my remote and local branch are divergent. I can only assume this has something to do with rebasing, and that my original commits where tampered with.

Output from git log:
% git log
commit 09e76b90aa1c0c3f6a780c8b29b0c93dc2f57143 (HEAD -> master, origin/master)
Author: John Doe <john@doe.com>
Date:   Wed Apr 12 13:23:12 2023 +0200

    1st imputation success no interaction or random sl

commit 2ef860eabd90dfff5197c66a3dbb541174e1146b
Author: John Doe <john@doe.com>
Date:   Thu Mar 9 22:32:49 2023 +0800

    First commit on Arch Linux

History on GitHub:

远程提交日期与本地不对应

  • Why do the commit dates on the local and remote branch diverge?

  • Is there a way to change Git/GitHub's behaviour so that the commit dates correspond?

答案1

得分: 2

它谈论的是提交日期,日志输出显示作者日期。如果你在日志中显示提交日期,你会发现它们是匹配的。尝试使用 git log --pretty=fuller 命令。


关于第二个问题:

为了将提交日期更改为对应作者日期,git rebase 提供了 --committer-date-is-author-date 选项。 使用添加了该标志的 rebase 操作,然后强制推送到远程仓库,解决了这个特定情况下的问题。

代码示例:

git rebase --committer-date-is-author-date HEAD~2
git push -f origin master
英文:

It's talking about commit dates, and the output from log shows author date. If you showed the commit dates in log, you would see that there is a match. Try with git log --pretty=fuller


With regards to the second question:

In order to change the commit dates to correspond to author dates, git rebase has --committer-date-is-author-date for this purpose. Rebase with the added flag and then force-pushing to remote resolved the issue for this particular case.

Code example:

git rebase --committer-date-is-author-date HEAD~2
git push -f origin master

huangapple
  • 本文由 发表于 2023年4月17日 16:17:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033034.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定