git rebase --committer-date-is-author-date --root不起作用 [英] git rebase --committer-date-is-author-date --root does not work
问题描述
我尝试将最新提交的提交者日期设置为其作者日期。通常,这可用于 git rebase --committer-date-is-author-date HEAD〜1
。不幸的是,只有一次提交,这意味着我必须使用-root
而不是 HEAD〜1
但要使用 git rebase --committer-date-is-author-date --root
出于某种原因未将提交者日期设置为作者日期。我该怎么办?
坏消息
不幸的是 git rebase --root
使用交互式rebase代码(因为非交互式代码无法重播根提交)和-committer-date -is-author-date
实际上是传递给 git am
的标志,它实现了简单的非交互情况。
好消息
git rebase
的基本功能是什么,是 copy 的一些提交(通常在复制过程中进行了某种更改),然后将分支名称指向最终的此类复制提交。如果只有一个要在复制时更改的提交,则可以使用 git commit --amend
代替 git rebase
。 1 如果整个存储库中只有一次提交,那么复制时就只需要更改一次,因此将适用这种情况。
您将需要使用 GIT_COMMITTER_DATE代替
变量,以将提交时间戳记设置为任意值。您还可以使用-提交日期是作者日期
-author
和/或-date
覆盖作者姓名和/或时间戳。 。因此:
t ='2017-09-01 12:34:56'
GIT_COMMITTER_DATE = $ t git commit --amend --date = $ t
将两个时间戳都设置为9月1日2017年,在12:34:56。 (我在这里使用了一个shell变量 t
以避免两次输入相同的时间戳。)
(添加-no-edit
如果您不想编辑提交消息,请记住,新的提交将使用索引中当前使用的内容!提取HEAD提交,您可能需要先将 HEAD
提交复制到临时索引,然后使用它。)
< hr>
1 这假设您要进行的更改是,例如,提交消息的文本或日期或作者等,而不是提交的父级ID。根提交的定义是没有父ID的,而 git commit --amend
将继续没有父ID,在这种情况下,这就是您想要的。 / p>
I try to set the committer date of the latest commit to its author date. Usually this works with git rebase --committer-date-is-author-date HEAD~1
. Unfortunately there is only one commit which means that I have to use --root
instead of HEAD~1
but git rebase --committer-date-is-author-date --root
does not set the committer date to the author date for some reason. What can I do?
The bad news
Unfortunately git rebase --root
uses the interactive rebase code (because the non-interactive code cannot "replay" the root commit), and --committer-date-is-author-date
is actually a flag passed to git am
, which implements the simple non-interactive cases.
The good news
What git rebase
does, at a fundamental level, is copy some commits (with, usually, some sort of change made during the copying process), then point a branch name at the final such copied commit. If there is just one commit you want to change-while-copying, you can use git commit --amend
instead of git rebase
.1 If there is only one commit in the entire repository, there can only be one commit that you need to change-while-copying, so this case will apply.
Instead of --committer-date-is-author-date
, you will need to use the GIT_COMMITTER_DATE
variable to set the commit time stamp to some arbitrary value. You can also use --author
and/or --date
to override the author name and/or time-stamp. Hence:
t='2017-09-01 12:34:56'
GIT_COMMITTER_DATE="$t" git commit --amend --date="$t"
would set both time stamps to September 1st of 2017, at 12:34:56. (I used a shell variable t
here to avoid typing in the same time stamp twice.)
(Add --no-edit
if you don't want to edit the commit message. Remember that the new commit will use whatever is currently in the index! If you have changed the index since extracting the HEAD commit, you may want to copy the HEAD
commit to a temporary index first, and use that.)
1This assumes the change you want to make is, e.g., the commit message text or date or author or some such, rather than the commit's parent ID. The definition of a root commit is one with no parent ID, and git commit --amend
will continue to have no parent ID, which is what you want in this case.
这篇关于git rebase --committer-date-is-author-date --root不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!