GIT:将提交日期更改为作者日期 [英] GIT: change commit date to author date

查看:598
本文介绍了GIT:将提交日期更改为作者日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将提交日期从我的提交更改为作者日期?

Is it possible to change the commit date from my commit to the author date?

我修改了一些提交,现在的日期都一样了.我想将其设置回旧日期(或作者日期).这可能吗?

I adapted some commits and now the dates are all the same. I want to set it back to the old dates (or the author dates). Is this possible?

我正在使用Sourcetree,所以我有git命令行,但我不是专业人士.我的外部存储库是bitbucket.

I am using Sourcetree so I have the git command line but I am not a pro at that. My external repository is bitbucket.

推荐答案

因为git 1.6.3 git rebase为此具有--committer-date-is-author-date.

Since git 1.6.3 git rebase has --committer-date-is-author-date for this purpose.

git rebase --committer-date-is-author-date

原始答案:
没有简单的方法来设置提交人日期(但请参见下面的编辑2"). author 日期易于调整(在提交时),因为--date可让您随时指定每个日期.

Original answer:
There's no easy way to set the committer dates (edit: but see "edit 2" below). The author dates are easy to adjust (at commit time) since --date will let you specify each one as you go.

环境变量GIT_COMMITTER_DATE可用于在进行提交时强制使用不同的时间戳.但是请注意,您需要针对重播"的每个提交进行调整.产生的新提交将具有不同的SHA-1(因为您已更改其中的一些位,即提交者日期字段),这意味着您必须重做其所有后代提交.

The environment variable GIT_COMMITTER_DATE can be used to force a different time stamp at the time you make the commit. Note, however, that you'd need to adjust this for each commit you "replay". The resulting new commit will have a different SHA-1 (because you've changed some bits in it, namely, the committer date field), which means you must redo all its descendent commits.

git filter-branch的工作方式(重新创建一些,许多或所有提交,并在此过程中进行更改,保持旧SHA-1 ID到新SHA-1 ID的映射,并调整偶数-否则保持不变的提交副本,以使新SHA-1 ID的新" DAG以各种可能的方式与旧" DAG匹配,即,除SHA-1 ID和过滤器所做的任何其他更改以外,以各种方式进行匹配)).

This is what git filter-branch does (re-create some, many, or all commits with changes made along the way, keeping a mapping from old SHA-1 IDs to new SHA-1 IDs and adjusting the parents of even-otherwise-untouched commit copies so that the "new" DAG of new SHA-1 IDs matches the "old" DAG in every possible way, i.e., in every way except for SHA-1 IDs and any other changes made by your filter(s)).

换句话说,要执行此操作,必须使用git filter-branch重写历史记录以及所有这一切.

In other words, to do this, you must use git filter-branch to rewrite history, with all that this implies.

编辑2 :如注释中所述(已删除),git rebase为此具有--committer-date-is-author-date.它仍然进行相同的历史记录重写,但是比使用raw git filter-branch命令进行操作要方便得多.

Edit 2: as eis noted in a comment (since removed), git rebase has --committer-date-is-author-date for this purpose. It still does the same history rewriting, but it's a lot more convenient than doing it with the raw git filter-branch command.

这篇关于GIT:将提交日期更改为作者日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆