在重写子模块的 git 历史记录后更新对父存储库中子模块的引用
Update references to a submodule in parent repository after submodule's git history is re-written
以下是我用来重写在多个父存储库中引用的子模块的历史记录的脚本。这在 windows 环境中的 Git bash 中运行。
#!/bin/bash
cd submodule_repo
git filter-branch --index-filter 'git rm -q --cached --ignore-unmatch files_to_remove' \--tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now
我需要以某种方式将旧提交的 SHAs 映射到新创建的 SHAs,以便我可以更新父存储库中的相同引用。有办法吗?我确实查看了 ,但它并没有真正帮助,因为我正在更新原始引用以确保我正在删除的文件不会被重新打包。我对使用 git 比较陌生,因此非常感谢任何指导。
编辑:
按照已接受答案(来自@torek)的评论部分中提到的步骤对我有用。
没有好的方法来做到这一点(至少使用 git filter-branch
和现有的 Git 工具——BFG 留下了所需的地图文件,但仍然需要构建一些东西)。
当git filter-branch
复制提交时,它会将每个新提交的哈希放入"map file"(将新旧ID配对——实际上是现有实现中的一个目录,尽管这在大过滤器,所以它可能有一天会被改变),这样就可以从原始提交哈希转换为重写提交哈希。这就是它提供 the git filter-branch
documentation 在这里引用的 map
函数的方式:
A map function is available that takes an "original sha1 id" argument and outputs a "rewritten sha1 id" if the commit has been already rewritten, and "original sha1 id" otherwise; the map function can return several ids on separate lines if your commit filter emitted multiple commits.
不幸的是,当 git filter-branch
完成并清理时,它 删除了 映射 table,而不是将其变成有用的数据库。如果您拥有包含映射的数据库,则可以将其与任何外部项目一起使用("gitlink" 条目在其他存储库、测试框架或您可能保存它们的任何其他地方)。没有地图,就没有好的方法来处理这个问题。超级项目说,例如 "use commit 1234567" 但该提交不再存在于重写的子模块存储库中。新提交的 ID 将在映射中 ,但没有映射。
以下是我用来重写在多个父存储库中引用的子模块的历史记录的脚本。这在 windows 环境中的 Git bash 中运行。
#!/bin/bash
cd submodule_repo
git filter-branch --index-filter 'git rm -q --cached --ignore-unmatch files_to_remove' \--tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now
我需要以某种方式将旧提交的 SHAs 映射到新创建的 SHAs,以便我可以更新父存储库中的相同引用。有办法吗?我确实查看了
编辑:
按照已接受答案(来自@torek)的评论部分中提到的步骤对我有用。
没有好的方法来做到这一点(至少使用 git filter-branch
和现有的 Git 工具——BFG 留下了所需的地图文件,但仍然需要构建一些东西)。
当git filter-branch
复制提交时,它会将每个新提交的哈希放入"map file"(将新旧ID配对——实际上是现有实现中的一个目录,尽管这在大过滤器,所以它可能有一天会被改变),这样就可以从原始提交哈希转换为重写提交哈希。这就是它提供 the git filter-branch
documentation 在这里引用的 map
函数的方式:
A map function is available that takes an "original sha1 id" argument and outputs a "rewritten sha1 id" if the commit has been already rewritten, and "original sha1 id" otherwise; the map function can return several ids on separate lines if your commit filter emitted multiple commits.
不幸的是,当 git filter-branch
完成并清理时,它 删除了 映射 table,而不是将其变成有用的数据库。如果您拥有包含映射的数据库,则可以将其与任何外部项目一起使用("gitlink" 条目在其他存储库、测试框架或您可能保存它们的任何其他地方)。没有地图,就没有好的方法来处理这个问题。超级项目说,例如 "use commit 1234567" 但该提交不再存在于重写的子模块存储库中。新提交的 ID 将在映射中 ,但没有映射。