首次提交的更改(不更改日期)

时间:2018-10-19 19:14:20

标签: git gitlab

我想对存储库中的第一次提交添加更改。 我做了以下命令:

git tag root `git rev-list HEAD | tail -1`
git checkout -b new-root root
// changes in code
git add .
GIT_COMMITTER_DATE="Mon Oct 1 22:36:58 2018 +0200"
git commit --amend --no-edit --date="Mon Oct 1 22:36:58 2018 +0200"
git checkout @{-1}
git rebase --onto new-root root --committer-date-is-author-date
git branch -d new-root
git tag -d root
git push origin master --force

除了文件列表(GitLab)中的所有内容之外,其他所有内容都没有任何修改,而是将Date更新为新内容:

screenshot from GitLab

screenshot from GitLab

谁能告诉我如何改进它?预先谢谢你!

2 个答案:

答案 0 :(得分:0)

只需确保不忽略您的最后一个参数,您可以使用以下命令重复序列吗?

 git rebase --committer-date-is-author-date --onto new-root root 
 # instead of
 git rebase --onto new-root root --committer-date-is-author-date

您首先需要使用git refloggit reset --hard ORIG_HEAD恢复root分支。

然后先使用以下方法检查重新设置基准前后根分支的作者/提交者日期:

git log --graph --pretty=format:"%aD --- %cD" root

答案 1 :(得分:0)

我认为您的新第一次提交(new-root)是错误的。这些命令仅设置作者日期,而不设置提交者日期,因为GIT_COMMITTER_DATE的值不会传播到git commit中。

GIT_COMMITTER_DATE="Mon Oct 1 22:36:58 2018 +0200"
git commit --amend --no-edit --date="Mon Oct 1 22:36:58 2018 +0200"

最简单的解决方案是在换行符之前添加尾随\

GIT_COMMITTER_DATE="Mon Oct 1 22:36:58 2018 +0200" \
git commit --amend --no-edit --date="Mon Oct 1 22:36:58 2018 +0200"

现在git commit看到了该变量。

相关问题