Замена даты коммитов в GIT
Хочу добавить существующий репозиторий на GitHub. Так как он отображает дату коммита из поля CommitDate, то для всех коммитов хочу выставить CommitDate равное AuthorDate. Для команды git rebase нашёл опцию --committer-date-is-author-date. Выполнил для всех коммитов, начиная от самых древних. Но у начального коммита дата не изменилась. Собственно говоря, почему?
user@PC ~/myrepo
$ git rebase --committer-date-is-author-date e727c96
First, rewinding head to replay your work on top of it...
Применение: Return correct error code in error callback
Применение: Move files to root folder
user@PC ~/myrepo
$ git rebase --committer-date-is-author-date 9e61101
First, rewinding head to replay your work on top of it...
Применение: Move files to root folder
user@PC ~/myrepo
$ git rebase --committer-date-is-author-date a0c1b7a
First, rewinding head to replay your work on top of it...
Fast-forwarded master to a0c1b7a.
user@PC ~/myrepo
$ git log --pretty=fuller
commit a0c1b7a9d5c331a088555567d20631d94c107523 (HEAD -> master, origin/master)
Author: XXXX <xxxx@xxxx>
AuthorDate: Sun Jan 10 13:25:15 2021 +0300
Commit: XXXX <xxxx@xxxx>
CommitDate: Sun Jan 10 13:25:15 2021 +0300
Move files to root folder
commit 9e611015ee95fbacf0ee267e0770c1eeda28b8aa
Author: XXXX <xxxx@xxxx>
AuthorDate: Sun Jun 14 21:34:58 2020 +0300
Commit: XXXX <xxxx@xxxx>
CommitDate: Sun Jun 14 21:34:58 2020 +0300
Return correct error code in error callback
commit e727c9609b0787d8b93f0570cd36389a36cc79f0
Author: XXXX <xxxx@xxxx>
AuthorDate: Tue Mar 31 19:32:50 2020 +0300
Commit: XXXX <xxxx@xxxx>
CommitDate: Sun Jan 10 13:16:23 2021 +0300
Initial commit
Ответы (1 шт):
Но у начального коммита дата не изменилась. Собственно говоря, почему?
при выполнении
$ git rebase --committer-date-is-author-date хэш
изменяется коммит, являющийся потомком коммита с указанным хэшем. т.е., для изменения некогего коммита надо указать хэш его предка.
а у самого первого коммита в истории предка нет. соответственно, подобной командой изменить самый первый коммит невозможно.
для всех коммитов хочу выставить CommitDate равное AuthorDate
этого можно добиться, например, командой filter-branch с опцией --commit-filter. вот так будут изменены даты «committer date» у всех коммитов, достижимых из того, на который указывает спецуказатель HEAD:
$ git filter-branch --commit-filter 'GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" git commit-tree "$@"'
иллюстрация. сначала:
$ git log --pretty=fuller
commit aef63a9e414abf06c92bae83c14269b1fa2b59a2 (HEAD -> master)
Author: user <user@host>
AuthorDate: Wed Jan 1 01:01:02 2020 +0300
Commit: user <user@host>
CommitDate: Sun Feb 2 02:02:02 2020 +0300
2
commit e6efa87163649f328700d60f54f3a3cc587266aa
Author: user <user@host>
AuthorDate: Wed Jan 1 01:01:01 2020 +0300
Commit: user <user@host>
CommitDate: Sun Feb 2 02:02:02 2020 +0300
1
меняем дату:
$ git filter-branch --commit-filter 'GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" git commit-tree "$@"'
Rewrite aef63a9e414abf06c92bae83c14269b1fa2b59a2 (2/2) (0 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
$ git log --pretty=fuller
commit 4ad12c93f15065fcd6174807bd6b9fa7ccee02f6 (HEAD -> master)
Author: user <user@host>
AuthorDate: Wed Jan 1 01:01:02 2020 +0300
Commit: user <user@host>
CommitDate: Wed Jan 1 01:01:02 2020 +0300
2
commit 5ef4883905240a32a4906af741dcca7e2daf8c05
Author: user <user@host>
AuthorDate: Wed Jan 1 01:01:01 2020 +0300
Commit: user <user@host>
CommitDate: Wed Jan 1 01:01:01 2020 +0300
1