Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git模拟来自其他存储库的旧提交 为什么?_Git_Git Commit_Git Rewrite History - Fatal编程技术网

git模拟来自其他存储库的旧提交 为什么?

git模拟来自其他存储库的旧提交 为什么?,git,git-commit,git-rewrite-history,Git,Git Commit,Git Rewrite History,在我们公司,我们开始使用一些开源代码并开始修补它。我现在想公开这些更改,所以我想用正确的作者和作者日期来应用这些更改(我不想因为我没有做的工作而受到表扬) 问题: 在company repo中,我有一个commit123456789,我想模仿它 在newrepo中,我准备了一个提交(使用gitadd-p) 现在我想创建一个commit,它模仿来自公司repo的commit123456789,但是在新repo中创建这个commit 思想 git commit-C可以从另一个commit获取g

在我们公司,我们开始使用一些开源代码并开始修补它。我现在想公开这些更改,所以我想用正确的作者和作者日期来应用这些更改(我不想因为我没有做的工作而受到表扬)

问题:
  • company repo
    中,我有一个commit
    123456789
    ,我想模仿它
  • newrepo
    中,我准备了一个提交(使用
    gitadd-p
现在我想创建一个commit,它模仿来自
公司repo
的commit
123456789
,但是在
新repo
中创建这个commit

思想
  • git commit-C
    可以从另一个commit获取git commit消息,但失败(
    无法查找commit
  • 因为这是跨两个不同的存储库的,所以可能需要创建一个补丁?但由于文件名已更改,这将变得复杂
  • 只是解析所需的信息并重用?应该复制什么?时间戳、提交消息、其他

    • 我不知道是否有更简单的方法,但我会解析作者消息时间戳,并在提交时重用它们

      正确设置这两个变量:

      OLDREPO=/path/to/company-repo
      HASH=123456789 # hash of commit to mimic
      
      然后可以从旧提交中提取值:

      DATE=$(git --git-dir=$OLDREPO/.git/ show --no-patch --no-notes --pretty='%cd' $HASH)
      AUTHOR=$(git --git-dir=$OLDREPO/.git/ show --no-patch --no-notes --pretty='%an <%ae>' $HASH)
      MESSAGE="$(git --git-dir=$OLDREPO/.git/ show --no-patch --no-notes --pretty='%B' $HASH)"
      

      注意:我不是故意设置提交人日期的。从技术上讲,提交是在今天创建的,而作者很久以前就编写了他的代码。

      这几乎就是要走的路。是否设置提交者信息也取决于您。如果您想设置所有六个项目(姓名、电子邮件、时间戳X作者、提交人),那么如果您想实现对称性,有六个env变量<代码>--author设置六个选项中的两个
      --date
      设置一个,因此如果您愿意,可以使用它来代替GIT\u AUTHOR\u date。您在谈论哪六项?我看到GIT_提交人日期,GIT_作者日期,可能还有两个来设置作者和提交人的身份?还有什么?谢谢你关于
      --date
      的提示,这确实会更加对称。六个环境变量是
      GIT{AUTHOR,committer}{NAME,EMAIL,date}
      git commit --author="$AUTHOR" --date="$DATE" -m "$MESSAGE"