GIT:将提交日期更改为作者日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28536980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GIT: change commit date to author date
提问by kevingoos
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?
我调整了一些提交,现在日期都一样了。我想将其设置回旧日期(或作者日期)。这可能吗?
I am using Sourcetree so I have the git command line but I am not a pro at that. My external repository is bitbucket.
我正在使用 Sourcetree,所以我有 git 命令行,但我不是专业人士。我的外部存储库是 bitbucket。
采纳答案by torek
Since git 1.6.3 git rebase
has --committer-date-is-author-date
for this purpose.
由于git的1.6.3git rebase
具有--committer-date-is-author-date
用于这一目的。
git rebase --committer-date-is-author-date
Original answer:
There's no easy way to set the committerdates (edit: but see "edit 2" below). The authordates are easy to adjust (at commit time) since --date
will let you specify each one as you go.
原始答案:
没有简单的方法来设置提交者日期(编辑:但请参阅下面的“编辑 2”)。在笔者的日期是容易调整(在提交时),因为--date
会让你指定你去每一个。
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_COMMITTER_DATE
可用于在您进行提交时强制使用不同的时间戳。但是请注意,您需要为您“重播”的每个提交调整它。生成的新提交将具有不同的 SHA-1(因为您更改了其中的某些位,即提交者日期字段),这意味着您必须重做其所有后代提交。
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
做的(重新创建一些、许多或所有提交,并在此过程中进行更改,保持从旧 SHA-1 ID 到新 SHA-1 ID 的映射,并调整即使在其他情况下未触及的提交副本的父项,以便新 SHA-1 ID 的“新”DAG 以各种可能的方式与“旧”DAG 匹配,即除了 SHA-1 ID 和您的过滤器所做的任何其他更改之外的所有方式)。
In other words, to do this, you must use git filter-branch
to rewrite history, with all that this implies. [Edit: you can literally do it without git filter-branch
, e.g., by doing it in git rebase -i
instead, but the effect is the same.]
换句话说,要做到这一点,您必须使用git filter-branch
重写历史,这意味着一切。[编辑:您可以不使用git filter-branch
,例如,git rebase -i
改为使用 ,但效果是相同的。]
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.
编辑2:如EIS在注释中(因为删除)指出,git rebase
有--committer-date-is-author-date
此目的。它仍然进行相同的历史重写,但比使用原始git filter-branch
命令更方便。
回答by jsphpl
Short Answer:
简答:
git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'
Explanation:
解释:
filter-branch
lets you rewrite your git history. It can apply transformations to each commit or filter out commits based on certain criteria. See git filter-branch --help
for a comprehensive description and usage instructions.
filter-branch
让你重写你的 git 历史。它可以将转换应用于每个提交或根据特定标准过滤掉提交。有关git filter-branch --help
全面的说明和使用说明,请参见。
--env-filter
allows you to set the environment variables that are present during the creation of the new history. It is evaluated for each commit separately.
--env-filter
允许您设置在创建新历史记录期间存在的环境变量。它为每个提交单独评估。