【问题标题】:Changes in first commit (without date changing)第一次提交的更改(不更改日期)
【发布时间】:2019-03-24 17:09:40
【问题描述】:

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

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) 中,那些未被任何提交修改的文件的日期更新为新的:

谁能告诉我如何改进它?提前谢谢你!

【问题讨论】:

    标签: git gitlab


    【解决方案1】:

    为了确保您的最后一个参数不会被忽略,您能否重复您的序列:

     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 分支。

    然后在 rebase 之前和之后首先检查根分支的作者/提交者日期:

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

    【讨论】:

      【解决方案2】:

      我认为您的新第一次提交 (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 看到了变量。

      【讨论】:

        猜你喜欢
        • 2012-01-23
        • 2020-07-06
        • 2011-01-15
        • 2012-10-13
        • 2022-01-09
        • 2018-04-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多